2017-07-22 11 views
0

を使用してエラー「not_x_content_exception」を取得:私はここにCURLを-使用しています、私はマッピングとそのプロパティElasticsearch 5.5私は、エラーの下に取得していますCURL

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 

を作成しようとしているとき)

は私のコードですCodeIgniterのを使用し、ここで

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

をelasticsearchすることは私のクラスファイルです:

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

コメントは、問題を特定しても、誰もがマッピングおよびプロパティを作成する方法を私に提案するか、完全にするためのマッピングに

+1

'curl_setopt($ ch、CURLOPT_VERBOSE、true);'を追加し、実行時に表示されるデバッグ情報を提供できますか? – Val

+1

あなたが送信しているJSON形式のデータで 'json_encode'を呼び出すと何か関係があるのでしょうか?Elasticsearch APIが処理しない文書があるのでしょうか?あなたがエンコードした後に正確に何が得られているかを確認することができますか、 'PUT'の場合に' json_encode'呼び出しを取り除こうとしますか? – Kdawg

+0

'json_encode'を正常に削除していただきありがとうございます –

答えて

1

を作成するための任意の別の方法があることができ、私は、答えとしてこれを追加しています。

このページ(https://github.com/elastic/elasticsearch-rails/issues/606)の回答によると、JSONドキュメントではなく文字列を送信すると、そのエラーが発生する可能性があります。

すでにJSONエンコードされた文字列のPUTにjson_encodeをコールすると、JSON以外のドキュメントがElasticsearchエンドポイントに送信されました。不要なjson_encodeを削除すると問題が解決されます。

関連する問題