Ruflin / Elastica + ES6的错误:不支持Content-Type标头[application / x-www-form-urlencoded]

时间:2018-12-19 20:09:33

标签: php elasticsearch header elastica

有人可以帮我解决从Ruflin / Elastica发送到Elasticsearch 6的标头的问题。似乎Ruflin / Elastica是旧版本,与Elasticsearch 6不太兼容。我发现here Elasticsearch的变化其行为与文档中的请求标头有关:从Elasticsearch 6.0开始,所有包含主体的REST请求还必须提供该主体的正确内容类型。

我无法更改Ruflin / Elastica库的版本,因此我想修复内容类型标头,但不知道该怎么做。有人可以帮我吗? 代码如下:

$query = sprintf('{
            "size": %s,
            "_source": %s,
            "query": {
                "bool": {
                    "filter": {
                        "terms": {
                            "ico": %s
                        }
                    }
                }
            }
        }', $this->limit, json_encode($cols), json_encode($icos));

$elastica = new Elastica\Client(["host" => 'localhost']);

$resp = $elastica->request('search_4/_search', Elastica\Request::POST, json_decode($query, TRUE))->getData();

0 个答案:

没有答案