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