Created
March 4, 2012 16:17
-
-
Save stratawing/1973719 to your computer and use it in GitHub Desktop.
ES Beginner's PHP Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.