Skip to content

Instantly share code, notes, and snippets.

@MrJohnsson77
Forked from stratawing/ES Beginner's PHP Script
Created September 4, 2012 04:42
Show Gist options
  • Save MrJohnsson77/3616672 to your computer and use it in GitHub Desktop.
Save MrJohnsson77/3616672 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;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment