yiisoft / yii2-elasticsearch

Yii 2 Elasticsearch extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
427 stars 253 forks source link

Error on document update #319

Closed ShostikSergey closed 1 year ago

ShostikSergey commented 2 years ago

Hi. I'm trying to use the library to work with elasticsearch 8.1. I'm getting an error when updating a record ` Exception 'yii\elasticsearch\Exception' with message 'Elasticsearch request failed with code 400. Response body: {"error":"no handler found for uri [/user-data-000001/_doc/IgHuyn8BFVoGVA2IEGZP/_update] and method [POST]"}'

in /usr/share/nginx/app/vendor/yiisoft/yii2-elasticsearch/Connection.php:558

Error Info: Array ( [requestMethod] => POST [requestUrl] => http://host.docker.internal:9200/user-data-000001/_doc/IgHuyn8BFVoGVA2IEGZP/_update [requestBody] => {"doc":{"updated_at":"2022-03-27 19:14:38"}} [responseCode] => 400 [responseHeaders] => Array ( [x-elastic-product] => Elasticsearch [content-type] => application/json [content-length] => 122 )

[responseBody] => Array
    (
        [error] => no handler found for uri [/user-data-000001/_doc/IgHuyn8BFVoGVA2IEGZP/_update] and method [POST]
    )

) `

In the official elasticsearch documentation, this type of urls is found up to version 6.8 inclusive. Starting from version 7, the url for updating documents looks like POST /index/_update/<_id>

Additional info

Q A
Yii version 2.0.45
yiisoft/yii2-elasticsearch 2.1.2
PHP version 7.3.33
Operating system gentoo
yuniorsk commented 1 year ago

Hey @ShostikSergey, you should add ['dslVersion' => 8] in your connection configuration.

ShostikSergey commented 1 year ago

Yes, of course, I specified ['dslVersion' => 8] in the elasticsearch connection parameters. But there was a url assembly error in the yiisoft/yii2-elasticsearch/Command.php. At the moment, this error has already been fixed.