简体   繁体   中英

Elasticsearch-py unrecognized 'analyzer' parameter in search()

The API Document says that search(*args, **kwargs) has a parameter called analyzer . But the following code raises an exception:

RequestError:TransportError(400, 'illegal_argument_exception', 'request [/test-index/content-field/_search] contains unrecognized parameter: [analyzer]')

from elasticsearch import Elasticsearch
from elasticsearch.client import IndicesClient
es = Elasticsearch()
res = es.search(index="test-index", doc_type='content-field',
                body={"query": {"match": {"text": "微观文明"}}},
                analyzer="ik_smart", size=3)

The following code, however, returns a correct answer.

i=IndicesClient(es)
res=i.analyze(index="test-index",body="我你大家",analyzer="ik_smart")

That parameter is only used (and accepted) when using the q parameter to search via a query string. In your case you need to specify the analyzer for the match query in the body[.]

Found the answer in this github issue: https://github.com/elastic/elasticsearch-py/issues/495

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM