Skip to content

Instantly share code, notes, and snippets.

@thangman22
Last active August 29, 2015 14:03
Show Gist options
  • Save thangman22/9efb35715591418050c6 to your computer and use it in GitHub Desktop.
Save thangman22/9efb35715591418050c6 to your computer and use it in GitHub Desktop.
Insert to Elastic
function insert_to_es($collection, $type, $id, $data, $ip = "localhost")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://' . $ip . ':9200/' . $collection . '/' . $type . '/' . $id);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$res = curl_exec($ch);
curl_close($ch);
}
function delete_from_es($collection, $type, $id, $ip = "localhost")
{
$url = 'http://' . $ip . ':9200/' . $collection . '/' . $type . '/' . $id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment