简体   繁体   English

Elasticsearch 5.5使用CURL获取错误'not_x_content_exception'

[英]Elasticsearch 5.5 getting error 'not_x_content_exception' using CURL

I'm getting below error: while I trying to create mapping and its properties 我遇到以下错误:在尝试创建映射及其属性时

Array
(
[error] => Array
    (
        [root_cause] => Array
            (
                [0] => Array
                    (
                        [type] => not_x_content_exception
                        [reason] => Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
                    )

            )

        [type] => not_x_content_exception
        [reason] => Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
    )

[status] => 500

)

I'm Using CURL-here is my code using Codeigniter and elasticsearch 我正在使用CURL-这是我使用Codeigniter和elasticsearch的代码

    $create ='
                {
                "properties": {
                    "message": {
                      "type": "text"
                        }
                  }
                }
                ';
    $response = $this->elasticsearch->custome_function("_mapping/tweet","PUT", $create);

Here is my class file: 这是我的课程文件:

class ElasticSearch
{
public $index;
/**
 * constructor setting the config variables for server ip and index.
 */
   public function __construct()
   {
    $ci = &get_instance();
    $ci -> config -> load("elasticsearch");
    $this -> server = 'http://localhost:9200'; //$ci -> config -> item('es_server');
    $this -> index = "my_index";        // configured in constant file //$ci -> config -> item('index');
}

private function call($path, $method = 'GET', $data = null)
{
    if (!$this -> index) {
        throw new Exception('$this->index needs a value');
    }
    $url = $this -> server . '/' . $this -> index . '/' . $path;
    $headers = array('Accept: application/json', 'Content-Type: application/json', );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    switch($method) {
        case 'GET' :
            break;
        case 'POST' :
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            break;
        case 'PUT' :
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
            break;
        case 'DELETE' :
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
            break;
    }
    $response = curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    return json_decode($response, true);
}


 public function custome_function($type,$method,$query)
 {
    return $this -> call($type,$method,$query);
 }
 }

Can anyone suggest me how to create mappings and properties or is there any alternate way to create mappings 谁能建议我如何创建映射和属性,或者有其他替代方法可以创建映射

For completeness, I'm adding this as an answer, though the comments identified the problem. 为了完整起见,我将其添加为答案,尽管评论指出了问题所在。

According to an answer on this page ( https://github.com/elastic/elasticsearch-rails/issues/606 ), that error can happen when you send in a string rather than a JSON document. 根据此页面上的答案( https://github.com/elastic/elasticsearch-rails/issues/606 ),当您发送字符串而不是JSON文档时,可能会发生该错误。

Calling the json_encode in the PUT on a string that was already JSON-encoded resulted in sending in a non-JSON document to the Elasticsearch endpoint. 在已使用JSON编码的字符串上在PUT中调用json_encode导致将非JSON文档发送到Elasticsearch端点。 Removing the unnecessary json_encode fixes the problem. 删除不必要的json_encode可解决此问题。

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

相关问题 使用ElasticSearch PHP客户端获取“ cURL错误7”连接到托管的ElasticSearch服务器 - Getting “cURL error 7” connecting to hosted ElasticSearch servers using ElasticSearch PHP Client 在laravel 5.5中的验证csrf令牌中未收到错误令牌不匹配异常 - not getting the error Token mismatch exception in Verify csrf token in laravel 5.5 没有从cURL得到任何错误消息或内容 - Not getting any error message or content from cURL 在PHP中使用Curl无法获取网页内容 - Not getting the content of webpage using Curl in Php 使用Elasticsearch的Curl Exception 7 PHP和Guzzle - Curl Exception 7 PHP and Guzzle with Elasticsearch 使用php和curl不断发布“缺少内容流”错误,以发布XML - Keep getting a “missing content stream” error using php and curl to post XML Laravel 5.5-Guzzle 6卷曲错误51 - Laravel 5.5 - Guzzle 6 curl error 51 使用php CURL从http发布获取内容主体 - Getting content body from http post using php CURL 为什么我收到致命错误:消息为“ cURL错误60”的未捕获异常“ GuzzleHttp \\ Exception \\ RequestException” - Why I am getting Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60 使用CURL获取内容后将表单序列化为POST - serialize form to POST after getting content using CURL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM