【发布时间】:2018-11-08 21:05:35
【问题描述】:
我正在尝试使用 Elasticsearch-php 5.0 版将搜索查询发送到 Elasticsearch 6.4.2。
从 5.0 到 6.0 的重大变化之一是存在“strict content type validation” 这意味着对 Elasticsearch 的请求必须使用“Content-type: application/json”标头发送。
为了添加这个标题,我尝试使用来自this thread的polyfractal的建议:
$params = [
'index' => $index,
'type' => $mapping,
'body' => $query,
'client' => [
'curl' => [CURLOPT_HTTPHEADER => array('Content-type: text/plain')]
]
];
$res = $this->mESClient->search($params); // this is Elasticsearch/Client
return $res;
但由于某种原因,当代码尝试执行curl_setopt_array() 时,我不断收到“注意:数组到字符串的转换”,并且请求是网络发送的。
请注意:当我删除 $params 数组的“客户端”部分时,Elasticsearch 会收到请求。
【问题讨论】:
-
你试过'curl' => [CURLOPT_HTTPHEADER => ['Content-type: text/plain']]。 array 和 [] 都是相同的,但想检查 Guzzle 是否有不同的想法。 :-)
标签: php elasticsearch