Skip to content

Instantly share code, notes, and snippets.

@stratawing
Created March 4, 2012 16:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save stratawing/1973719 to your computer and use it in GitHub Desktop.
Save stratawing/1973719 to your computer and use it in GitHub Desktop.
ES Beginner's PHP Script
<?php
$ch = curl_init();
$method = "GET";
$url = "localhost/cerberus/resraw/_search?pretty=true";
$qry = '{
"size" : 10,
"fields" : "usr",
"query" : {
"term" : { "usr":"stratawing"}
}
}';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, 9200);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($ch, CURLOPT_POSTFIELDS, $qry);
$result = curl_exec($ch);
curl_close($ch);
// use the following if you want your result in a php array
//var_dump(json_decode($result, true));
//use the following if you want the raw json format from es
echo $result;
?>
@prashanttct07
Copy link

Hi ,
I am using above script to index the data in bulk, so when i am inserting one document at a time its working fine but with bulk its giving the exception as below :

"error":"JsonParseException[Unexpected character (':' (code 58)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [B@14abb68; line: 1, column: 18]]","status":500}

Kindly find below code which I am using for the same and do let me know what could be wrong over here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment