简体   繁体   English

elasticsearch用php和curl更新文档

[英]elasticsearch update document with php and curl

I try to update one of my document with PHP and curl. 我尝试使用PHP和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';" “” $ payload“,对应于” $ value [“ title”] ='Shining';“ and i see json_encode... but I've got this error: 我看到json_encode ...但出现了这个错误:

[-] json_encode{"error":"ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]","status":500} [-] json_encode {“错误”:“ ActionRequestValidationException [验证失败:1:脚本或文档丢失;]”,“状态”:500}

How to resolve this error. 如何解决此错误。 thanks in advance. 提前致谢。

You can use the elasticsearch library ... it's really good. 您可以使用elasticsearch库...这真的很好。

https://github.com/elasticsearch/elasticsearch https://github.com/elasticsearch/elasticsearch

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

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