Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created September 19, 2014 06:59
Show Gist options
  • Save thangman22/177c805575dbfffbfcd7 to your computer and use it in GitHub Desktop.
Save thangman22/177c805575dbfffbfcd7 to your computer and use it in GitHub Desktop.
elasticsearch_function
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