I try to update one of my document with PHP and curl. I've got this source code:
protected function call($url, $method="GET", $payload=null) {
$conn = $this->ch;
$protocol = "http";
$requestURL = $protocol . "://" . $this->host .":9200". $url;
curl_setopt($conn, CURLOPT_URL, $requestURL);
curl_setopt($conn, CURLOPT_TIMEOUT, self::TIMEOUT);
curl_setopt($conn, CURLOPT_PORT, $this->port);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1) ;
curl_setopt($conn, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($conn, CURLOPT_FORBID_REUSE , 0) ;
if (is_array($payload) && count($payload) > 0)
{
echo "<br/>[-] json_encode";
curl_setopt($conn, CURLOPT_POSTFIELDS, json_encode($payload));
}
else
{
curl_setopt($conn, CURLOPT_POSTFIELDS, array($payload));
}
$response = curl_exec($conn);
if ($response !== false) {
$data = json_decode($response, true);
if (!$data) {
$data = array('error' => $response, "code" => curl_getinfo($conn, CURLINFO_HTTP_CODE));
}
}
else { //... error } }
etc ...}
"$payload", corresponding at "$value["title"] = 'Shining';" and i see json_encode... but I've got this error:
[-] json_encode{"error":"ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]","status":500}
How to resolve this error. thanks in advance.
You can use the elasticsearch library ... it's really good.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.