Skip to content

Instantly share code, notes, and snippets.

@reyhansofian
Forked from stratawing/ES Beginner's PHP Script
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reyhansofian/7a2b3581be22deb1428b to your computer and use it in GitHub Desktop.
Save reyhansofian/7a2b3581be22deb1428b to your computer and use it in GitHub Desktop.
<?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