yiisoft / yii2-elasticsearch

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

Suggests fail on elastic 6.5 #216

Closed Seb012007 closed 4 years ago

Seb012007 commented 5 years ago

On ElasticSearch 6.5 usage of "_suggest" is deprecated : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html

Note

_suggest endpoint has been deprecated in favour of using suggest via _search endpoint. In 5.0, the _search endpoint has been optimized for suggest only search requests.

What steps will reproduce the problem?

Use Elastic Search 6.5 :

{
  "name" : "node-1",
  "cluster_name" : "mpdb.tv",
  "cluster_uuid" : "jge2-YjGQ1iZ8h1_NYwoZw",
  "version" : {
    "number" : "6.5.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "816e6f6",
    "build_date" : "2018-11-09T18:58:36.352602Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

Use "yiisoft/yii2-elasticsearch": "2.1.x-dev"

Try to use suggest command :

Array
(
    [requestMethod] => POST
    [requestUrl] => http://127.0.0.1:9200/mpdb%3Asagas/_suggest
    [requestBody] => {"suggest":{"saga_suggest":{"prefix":"chos","completion":{"field":"suggest"}}}}
    [responseCode] => 400
    [responseHeaders] => Array
        (
            [content-type] => application/json; charset=UTF-8
            [content-length] => 271
        )

    [responseBody] => Array
        (
            [error] => Array
                (
                    [root_cause] => Array
                        (
                            [0] => Array
                                (
                                    [type] => invalid_type_name_exception
                                    [reason] => Document mapping type name can't start with '_', found: [_suggest]
                                )

                        )

                    [type] => invalid_type_name_exception
                    [reason] => Document mapping type name can't start with '_', found: [_suggest]
                )

            [status] => 400
        )

)

Solution :

On Command.php l.114 if I change :

        $url = [
            $this->index !== null ? $this->index : '_all',
            '_suggest'
        ];

By :

        $url = [
            $this->index !== null ? $this->index : '_all',
            '_search'
        ];

Everything ok.

May you update this part for Elastic > 6.5 versions? Hox could I override this?

Thanks,

Regards,

samdark commented 5 years ago

Do you use 2.1 branch?

Seb012007 commented 5 years ago

Yes I use this : "yiisoft/yii2-elasticsearch": "2.1.x-dev"
I found a workaround for myself but as the term "_suggest" is deprecated in favor of "_search"+ POST parameters I think you should make an update of this. See : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html

Regards,

beowulfenator commented 4 years ago

Fixed in #284.