I add data add Elasticsearch this code:
$data = array("name"=>HelperMC::strToUtf8(trim($name)),
"urlname"=>HelperURL::strToURL(trim($name)),
"price"=>number_format(HelperParser::clearTextFromPrice($price), 2, ',', '.'),
"price_for_filter"=>HelperParser::clearTextFromPrice($price),
"image"=>$imgname,
"description"=>HelperMC::strToUtf8($description),
"keywords"=>HelperMC::strToUtf8($keywords),
"url"=>$k['url'],
"sitemap_id"=>intval($sitemapId),
"shop_id"=>$shop['shop_id'],
"logo"=>$shop['logo'],
"key"=>$hashKey,
"type"=>intval(1),
"shop_rating_count"=>intval($shop['rating_count']),
"shop_rating_point"=>intval($shop['rating_point']),
"created_at"=>date("Y-m-d H:i:s"),
"updated_at"=>date("Y-m-d H:i:s"));
//create elasticsearch index
HelperES::insertEntry(json_encode($data),$hashKey);
My insertEntry Function:
private static $elasticBase = "http://localhost:9200/shopping/items";
public static function insertEntry($data_string,$id = false){
if($id)
$url = self::$elasticBase."/".$id;
else
$url = self::$elasticBase;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
#$result = curl_exec($ch);
curl_close($ch);
return $result;
}
and my search Function:
public static function search($keyword, $defaultOperator = "OR" ,$start = 0, $size = 25, $from = 0, $to = 10000, $shopsArr = array(),$orderBy = "price", $order = "asc"){
$searchUrl = self::$elasticBase."/_search";
if(count($shopsArr) > 0){
$query = '{
"from" : '.$start.', "size" : '.$size.',
"query" : {
"filtered" : {
"query": {
"query_string": { "query": "'.$keyword.'",
"fields": ["name","urlname"],
"default_operator": "'.$defaultOperator.'"
}
},
"filter" : {
"bool" : {
"must" : {
"terms" : { "sitemap_id" : '.json_encode($shopsArr).' }
},
"must" : {
"range" : {
"price_for_filter" : {
"from" : "'.$from.'",
"to" : "'.$to.'"
}
}
}
}
}
}
},
"sort" : [
{"'.$orderBy.'" : {"order" : "'.$order.'", "mode" : "avg"}}
]
}';
}else{
$query = '{
"from" : '.$start.', "size" : '.$size.',
"query" : {
"filtered" : {
"query": {
"query_string": {
"query": "'.$keyword.'",
"fields": ["name","urlname"],
"default_operator": "'.$defaultOperator.'"
}
},
"filter" : {
"range" : {
"price_for_filter" : {
"from" : "'.$from.'",
"to" : "'.$to.'"
}
}
}
}
},
"sort" : [
{"'.$orderBy.'" : {"order" : "'.$order.'", "mode" : "avg"}}
]
}';
}
echo $query;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $searchUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
#$result = curl_exec($ch);
curl_close($ch);
return $result;
}
But my search results not working.
Example: http://azdanaz.com:9200/shopping/items/_search?q=name:telefon&pretty
working but,
http://www.azdanaz.com/arama/telefon
not working.
Looking at the mapping for your shopping index, it shows that your price_for_filter field is actually a string, not a numeric type. Therefore, your range filter is doing a string comparison, not a numeric comparison. This is filtering out all of your results.
To illustrate, your range is filtering from "0" to "100000". The price_for_filter value of your first expected result is "12.97". When doing a string comparison, "12.97" is greater than "0", however, as a string, it is also greater than "100000", so this result gets filtered out ("12" > "10").
You either need to change the price_for_filter field to be a numeric field, or you need to add a new field that is a numeric type and change your range filter to use that new field.
Related
I'm using the FXHash API to access listings with this query:
query Listings($sort: ListingsSortInput) {
listings(sort: $sort) {
amount
createdAt
price
issuer {
name
}
objkt {
name
}
}
}
$options = '{
"sort": {
"createdAt": "DESC"
}
}';
I'd like to use the query above in PHP with the sort by createdAt options. How can I fit this query in to my cURL with the sort options? I don't understand how to add the $options variable into the query. Thanks for the help!
$url = 'https://api.fxhash.xyz/graphql';
$curl = curl_init();
$queryData = array();
$data = array();
$queryData = '{
listings {
amount
createdat
price
issuer {
name
}
objkt {
name
}
}
}';
$data["query"] = $queryData;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
You must add the POST request variables as a JSON map.
Try something like this:
$queryData = 'query Listings($sort: ListingsSortInput) {
listings(sort: $sort) {
amount
createdAt
price
issuer {
name
}
objkt {
name
}
}
}';
$options = '{
"sort": {
"createdAt": "DESC"
}
}';
$data["query"] = $queryData;
$data["variables"] = $options;
Following a successful response from an API Request to M-PESA where the following JSON code is printed:
{ "MerchantRequestID":"2690XXXXXXX", "CheckoutRequestID":"xx_XX_2779308581984", "ResponseCode": "0", "ResponseDescription":"Success. Request accepted for processing", "CustomerMessage":"Success. Request accepted for processing" }
I would like to access the data sent to my callback url: https://xxxxxxxxxxxxxxxxx.ngrok.io/processL/transact.php . Despite expecting the code to change accordingly upon cancellation or payment, nothing happens although when I inspect the response on the ngrok local tunnel online interface, I see my expected results only that I do not know how to acquire and generate some action with them. Below is the code making the API Request and the results which I expect to be sent to my call back url but in vain.
<!-- transact.php -->
<?php
if (isset($_POST['submit'])) {
$Passkey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$Amount= $_POST['amt'];
$BusinessShortCode = '174379';
$PartyA =$_POST['phone'];
$AccountReference =$_POST['name'];
$TransactionDesc = 'test';
$Timestamp =date('YmdHis');
$Password = base64_encode($BusinessShortCode.$Passkey.$Timestamp);
$headers=['Content-Type:application/json; charset=utf8'];
$initiate_url='https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest';
$callBackURL ='https://xxxxxxxxxxxxxxxxx.ngrok.io/processL/transact.php';
function accessToken() {
$ConsumerKey = 'ubYsxxxxxxxxxxxxx';
$ConsumerSecret = 'xxxxxxxxxxxxx';
$credentials = base64_encode($ConsumerKey.":".$ConsumerSecret);
$url = "https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Basic ".$credentials,"Content-Type:application/json"));
curl_setopt($curl, CURLOPT_HEADER, false);
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
$access_token=json_decode($curl_response);
curl_close($curl);
return $access_token->access_token;
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $initiate_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.accessToken()));
$curl_post_data = array(
'BusinessShortCode' =>$BusinessShortCode,
'Password' => $Password,
'Timestamp' => $Timestamp,
'TransactionType' => 'CustomerPayBillOnline',
'Amount' => $Amount,
'PartyA' => $PartyA,
'PartyB' => $BusinessShortCode,
'PhoneNumber' => $PartyA,
'CallBackURL' => $callBackURL,
'AccountReference' => $AccountReference,
'TransactionDesc' => $TransactionDesc
);
$data_string = json_encode($curl_post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
$curl_response = curl_exec($curl);
print_r($curl_response."<br>");
}
Upon acceptance of payment:
{
"Body": {
"stkCallback": {
"MerchantRequestID": "xxxxxxxxxxxxx",
"CheckoutRequestID": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"ResultCode": 0,
"ResultDesc": "The service request is processed successfully.",
"CallbackMetadata": {
"Item": [
{
"Name": "Amount",
"Value": 1
},
{
"Name": "MpesaReceiptNumber",
"Value": "xxxxxxxxxxxxx"
},
{
"Name": "Balance"
},
{
"Name": "TransactionDate",
"Value": 20210927101413
},
{
"Name": "PhoneNumber",
"Value": xxxxxxxxxxxxx
}
]
}
}
}
};
When payment is cancelled:
{
"Body": {
"stkCallback": {
"MerchantRequestID": "xxxxxxxxxxxxx",
"CheckoutRequestID": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"ResultCode": 1032,
"ResultDesc": "Request cancelled by user"
}
}
};
I need some guidance.
The documentation for json_decode() is your friend. If you pass true as the second argument then it returns your JSON data as associative arrays.
$access_token=json_decode($curl_response, true);
// Check the response value
$result = $access_token['Body']['stkCallback']['ResultCode'] ?? null;
if ($result == 0) {
// Success
}
still trying to get my head around API's and connections.
I am trying to do a buy order to Binance but keep getting a 400 response. I know it's been an issue for some others but I just can't seem to suss out where I am going wrong. So hoping someone can help me out.
It's only issues with POST's, all the GET requests are working fine, and so to the signature and timestamp... or at least I am getting responses for my account so I assume so.
The first CURL is just for the serverTime, but the second CURL is for a buy/sell order.
This is the response I am getting now...
"Object ( [code] => -1102 [msg] => Mandatory parameter 'side' was not
sent, was empty/null, or malformed. )"
If I type the in the string manually it works just fine, but for one reason or another when I pass $qs it presents the above fault. I echoed $qs to the screen and copied that instead of passing $qs and it worked when I put in the new timestamp. I am stumped...
"symbol=TRXUSDC&side=SELL&type=LIMIT&timeInForce=GTC&quantity=63000.00000000&price=0.02550000&recvWindow=1000000×tamp=1550922237310"
any advice?
$header = array('X-MBX-APIKEY:' . KEY);
$url = BINANCE . 'api/v1/time';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_URL,$url);
$response = curl_exec($curl);
if (FALSE === $response){
echo curl_error($curl), curl_errno($curl);
}
$serverTime = json_decode($response);
curl_close($curl);
$url = BINANCE . "api/v3/order";
$signature = NULL;
$queryString = NULL;
$query = array(
"symbol" => "TRXUSDC",
"side" => "SELL",
"type" => "LIMIT",
"timeInForce" => "GTC",
"quantity" => number_format(63000.00000000,8,'.',''),
"price" => number_format(0.02550000,8,'.',''),
"recvWindow" => 1000000,
"timestamp" => $serverTime->serverTime);
$qs = htmlentities(http_build_query(array_unique($query)));
$query['signature'] = hash_hmac('SHA256', $qs, SECRET );
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_ENCODING, "application/x-www-form-urlencoded");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl,CURLOPT_FAILONERROR,FALSE);
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS,$qs);
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
if (FALSE === $response){
echo curl_error($curl).':'.curl_errno($curl);
}
$obj = json_decode($response);
curl_close($curl);
I tried this code and var_dump $qs
symbol=BTCUSDT&side=BUY&...
so I think you must remove amp;
Based on Binance spot api docs:
It is recommended to use a small recvWindow of 5000 or less! The max cannot go beyond 60,000!
so edit your query params with:
"symbol=TRXUSDC&side=SELL&type=LIMIT&timeInForce=GTC&quantity=63000.00000000&price=0.02550000&recvWindow=60000×tamp=1550922237310"
Also you can check your other query params with exchange info that you can get with https://api.binance.com/api/v3/exchangeInfo that we have for your symbol:
{
"symbol": "TRXUSDC",
"status": "TRADING",
"baseAsset": "TRX",
"baseAssetPrecision": 8,
"quoteAsset": "USDC",
"quotePrecision": 8,
"quoteAssetPrecision": 8,
"baseCommissionPrecision": 8,
"quoteCommissionPrecision": 8,
"orderTypes": [
"LIMIT",
"LIMIT_MAKER",
"MARKET",
"STOP_LOSS_LIMIT",
"TAKE_PROFIT_LIMIT"
],
"icebergAllowed": true,
"ocoAllowed": true,
"quoteOrderQtyMarketAllowed": true,
"isSpotTradingAllowed": true,
"isMarginTradingAllowed": false,
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.00001000",
"maxPrice": "1000.00000000",
"tickSize": "0.00001000"
},
{
"filterType": "PERCENT_PRICE",
"multiplierUp": "5",
"multiplierDown": "0.2",
"avgPriceMins": 5
},
{
"filterType": "LOT_SIZE",
"minQty": "0.10000000",
"maxQty": "9000000.00000000",
"stepSize": "0.10000000"
},
{
"filterType": "MIN_NOTIONAL",
"minNotional": "10.00000000",
"applyToMarket": true,
"avgPriceMins": 5
},
{
"filterType": "ICEBERG_PARTS",
"limit": 10
},
{
"filterType": "MARKET_LOT_SIZE",
"minQty": "0.00000000",
"maxQty": "659177.02430556",
"stepSize": "0.00000000"
},
{
"filterType": "MAX_NUM_ORDERS",
"maxNumOrders": 200
},
{
"filterType": "MAX_NUM_ALGO_ORDERS",
"maxNumAlgoOrders": 5
}
],
"permissions": [
"SPOT"
]
}
for other possible reasons check spot api docs in the link https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md
I tested the code and saw a few glitches in it :
$qs = htmlentities(http_build_query(array_unique($query)));
gave me an error ({"code":-1102,"msg":"Mandatory parameter 'side' was not sent, was empty/null, or malformed."}), so i replaced it with:
$qs = http_build_query(array_unique($query));
After that you created your signature, but never added it to you request. So do the following :
$signature = hash_hmac('sha256', $qs, $apiSecret);
$qs .= "&signature=" . $signature;
Also update your 'recvWindow' to a max of 60000 (I suggest 50000 or less (see the answer of #Tofiq Samali)) and you are ready to go!
I want to use API of the constant contact and want to insert user Email Ids using PHP script while user register to the website.
I using following code for this.
$data['addresses'][0]['address_type'] = 'BUSINESS';
$data['addresses'][0]['city'] = 'Belleville';
$data['addresses'][0]['country_code'] = 'CA';
$data['addresses'][0]['line1'] = '47 Shawmut Ave.';
$data['addresses'][0]['line2'] = 'Suite 404';
$data['addresses'][0]['postal_code'] = '"K8b 5W6';
$data['addresses'][0]['state_code'] = 'ON';
$data['lists'][0]['id'] = "1554397204";
$data['cell_phone'] = "555-555-5555";
$data['company_name'] = "System Optimzations";
$data['confirmed'] = false;
$data['email_addresses'][0]['email_address'] = "username112#example.com";
$data['fax'] = "555-555-5555";
$data['first_name'] = "Manvendra";
$data['home_phone'] = "555-555-5555";
$data['job_title'] = "Systems Analyst 3";
$data['last_name'] = "Rajpurohit";
$data['prefix_name'] = "Mr.Martone";
$data['work_phone'] = "555-555-5555";
$jsonstring = json_encode($data);
// echo '<pre>'; print_r($data);
$posturl = "https://api.constantcontact.com/v2/contacts?action_by=ACTION_BY_OWNER&api_key=*******";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
// curl_setopt($ch, CURLOPT_USERPWD, $authstr);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonstring);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json",'Authorization: Bearer *****
','Content-Length: ' . strlen($jsonstring)));
curl_setopt($ch, CURLOPT_HEADER, false); // Do not return headers
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); // If you set this to 0, it will take you to a page with the http response
$response = curl_exec($ch);
if (FALSE === $response)
throw new Exception(curl_error($ch), curl_errno($ch));
echo '<pre>'; print_r($response); die;
curl_close($ch);
When I run this script then its showing following error.
[{"error_key":"json.payload.empty","error_message":"JSON payload cannot be empty."}]
Please help me that how can I resolve this error.
The actual problem is validation error,which is:-
[{"error_key":"json.max.length.violation","error_message":"#/prefix_name: Value exceeds maximum length of 4."}]
So what i did is changed:-
$data['prefix_name'] = "Mr.Martone";
To:-
$data['prefix_name'] = "tone"; // length need to be 4 or less only
And used this CURL request and data saved successfully.
<?php
$data['addresses'][0]['address_type'] = 'BUSINESS';
$data['addresses'][0]['city'] = 'Belleville';
$data['addresses'][0]['country_code'] = 'CA';
$data['addresses'][0]['line1'] = '47 Shawmut Ave.';
$data['addresses'][0]['line2'] = 'Suite 404';
$data['addresses'][0]['postal_code'] = '"K8b 5W6';
$data['addresses'][0]['state_code'] = 'ON';
$data['lists'][0]['id'] = "1554397204";
$data['cell_phone'] = "555-555-5555";
$data['company_name'] = "System Optimzations";
$data['confirmed'] = false;
$data['email_addresses'][0]['email_address'] = "username112#example.com";
$data['fax'] = "555-555-5555";
$data['first_name'] = "Manvendra";
$data['home_phone'] = "555-555-5555";
$data['job_title'] = "Systems Analyst 3";
$data['last_name'] = "Rajpurohit";
$data['prefix_name'] = "tone";
$data['work_phone'] = "555-555-5555";
$jsonstring = json_encode($data);
//echo '<pre>'; print_r($data);
$posturl = "https://api.constantcontact.com/v2/contacts?action_by=ACTION_BY_OWNER&api_key=*******";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonstring);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json",'Authorization: Bearer ******')); //check change here
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// this need to be 1
$response = curl_exec($ch);
if (FALSE === $response)
throw new Exception(curl_error($ch), curl_errno($ch));
echo '<pre>'; print_r($response); die;
curl_close($ch);
Output i got is:-
{
"id": "1519826644",
"status": "ACTIVE",
"fax": "555-555-5555",
"addresses": [{
"id": "9ac8fd40-c2b2-11e7-aa57-d4ae5284344f",
"line1": "47 Shawmut Ave.",
"line2": "Suite 404",
"line3": "",
"city": "Belleville",
"address_type": "BUSINESS",
"state_code": "ON",
"state": "Ontario",
"country_code": "ca",
"postal_code": "\"K8b",
"sub_postal_code": "5W6"
}],
"notes": [],
"confirmed": false,
"lists": [{
"id": "1554397204",
"status": "ACTIVE"
}],
"source": "API",
"email_addresses": [{
"id": "9a914b70-c2b2-11e7-aa57-d4ae5284344f",
"status": "ACTIVE",
"confirm_status": "NO_CONFIRMATION_REQUIRED",
"opt_in_source": "ACTION_BY_OWNER",
"opt_in_date": "2017-11-06T05:23:21.000Z",
"email_address": "username23333#example.com"
}],
"prefix_name": "tone",
"first_name": "Manvendra",
"middle_name": "",
"last_name": "Rajpurohit",
"job_title": "Systems Analyst 3",
"company_name": "System Optimzations",
"home_phone": "555-555-5555",
"work_phone": "555-555-5555",
"cell_phone": "555-555-5555",
"custom_fields": [],
"created_date": "2017-11-06T05:23:20.000Z",
"modified_date": "2017-11-06T05:23:20.000Z",
"source_details": "Web Devloping"
}
I am having problem with Elasticsearch script filter and Curl post URI.
I am passing the values using URL as below
My URL with parameters
$params = rawurlencode('firstName:John');
$url= 'http://localhost:9200/jdbc/_search?q='.$params.'&pretty=true';
My Json code:
$options='{
"query": {
"filtered": {
"filter": {
"script": {
"script": "(min..max).contains(doc.admitted_date.date.year)",
"params": {
"min": 1999,
"max": 2000
}
}
}
}
},
"aggs": {
"citycount": {
"cardinality": {
"field": "cityid",
"precision_threshold": 100
}
}
}
}';
Curl passing:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$options);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$data = ob_get_contents();
ob_end_clean();
When i pass the above query, it show wrong result. because we are passing parameters with URL and JSON in both formats. So one time it will take the parameters from URL only. Is there any way to pass both parameters or is there any other way to pass this? Is there any way to pass Script in URL in Elasticsearch PHP
The correct way of doing this is to pass everything in the query, including the match on the firstName field:
$options='{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "firstName:John"
}
},
"filter": {
"script": {
"script": "(min..max).contains(doc.admitted_date.date.year)",
"params": {
"min": 1999,
"max": 2000
}
}
}
}
},
"aggs": {
"citycount": {
"cardinality": {
"field": "cityid",
"precision_threshold": 100
}
}
}
}';
$url= 'http://localhost:9200/jdbc/_search?pretty=true';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1); <---- also add this
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$data = ob_get_contents();
ob_end_clean();