繁体   English   中英

elasticsearch用php和curl更新文档

[英]elasticsearch update document with php and curl

我尝试使用PHP和curl更新我的文档之一。 我有此源代码:

     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 } }

等等...}

“” $ payload“,对应于” $ value [“ title”] ='Shining';“ 我看到json_encode ...但出现了这个错误:

[-] json_encode {“错误”:“ ActionRequestValidationException [验证失败:1:脚本或文档丢失;]”,“状态”:500}

如何解决此错误。 提前致谢。

您可以使用elasticsearch库...这真的很好。

https://github.com/elasticsearch/elasticsearch

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM