elasticsearch php Content-Type header [] is not supported

  作者:会飞的

Content-Typeheader[]isnotsupportedif(is_null($this->connectionFactory)){if(is_null($this->connectionParams)){$this->connectionParams=[];}//MakesurewearesettingContent-TypeandAccept(unlesstheuserhasexplicitly//overriddenit//解决办法,需要在
Content-Type header [] is not supported

if (is_null($this->connectionFactory)) {
    if (is_null($this->connectionParams)) {
        $this->connectionParams = [];
    }

    // Make sure we are setting Content-Type and Accept (unless the user has explicitly
    // overridden it
    //解决办法,需要在header增加json
    if (isset($this->connectionParams['client']['headers']) === false) {
        $this->connectionParams['client']['headers'] = [
            'Content-Type' => ['application/json'],
            'Accept' => ['application/json']
        ];
    } else {
        if (isset($this->connectionParams['client']['headers']['Content-Type']) === false) {
            $this->connectionParams['client']['headers']['Content-Type'] = ['application/json'];
        }
        if (isset($this->connectionParams['client']['headers']['Accept']) === false) {
            $this->connectionParams['client']['headers']['Accept'] = ['application/json'];
        }
    }

    $this->connectionFactory = new ConnectionFactory($this->handler, $this->connectionParams, $this->serializer, $this->logger, $this->tracer);
}


linux命令

curl -H "Content-Type: application/json" http://localhost:9200/index/_search?pretty -d ' {"query": {"match_all": {}}}'

有用  |  无用

猜你喜欢