gpt4 book ai didi

php - 将 Content-type header 设置为 Elasticsearch-php 客户端

转载 作者:行者123 更新时间:2023-11-29 02:55:59 26 4
gpt4 key购买 nike

我正在尝试使用 Elasticsearch-php 5.0 版将搜索查询发送到 Elasticsearch 6.4.2。

从 5.0 到 6.0 的重大变化之一是有“strict content type validation”这意味着对 Elasticsearch 的请求必须使用“Content-type: application/json” header 发送。

为了添加这个标题,我尝试使用 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 正在接收请求。

最佳答案

根据 Version Matrix ,处理 ES >=6 时应该使用 elasticsearch-php 6.0。

elasticsearch-php 5.0 与 ElasticSearch 6 不兼容。

您提到的线程与 ES-PHP 1.x/2.x 相关,它们可能具有不同的选项语法。这与您的情况无关,除了其中一条评论与我在上面所做的相同。

FYI, if you're using Elasticsearch 6.0+, you need to upgrade your ES-PHP client to the 6.0 branch too. ES-PHP 6.0+ sets the content-type headers automatically: fd3b0f1

关于php - 将 Content-type header 设置为 Elasticsearch-php 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53207255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com