[英]Getting “cURL error 7” connecting to hosted ElasticSearch servers using ElasticSearch PHP Client
[英]Elasticsearch 5.5 getting error 'not_x_content_exception' using 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
)
我正在使用CURL-這是我使用Codeigniter和elasticsearch的代碼
$create ='
{
"properties": {
"message": {
"type": "text"
}
}
}
';
$response = $this->elasticsearch->custome_function("_mapping/tweet","PUT", $create);
這是我的課程文件:
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);
}
}
誰能建議我如何創建映射和屬性,或者有其他替代方法可以創建映射
為了完整起見,我將其添加為答案,盡管評論指出了問題所在。
根據此頁面上的答案( https://github.com/elastic/elasticsearch-rails/issues/606 ),當您發送字符串而不是JSON文檔時,可能會發生該錯誤。
在已使用JSON編碼的字符串上在PUT中調用json_encode
導致將非JSON文檔發送到Elasticsearch端點。 刪除不必要的json_encode
可解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.