简体   繁体   English

搜索()中的Elasticsearch-py无法识别的'analyzer'参数

[英]Elasticsearch-py unrecognized 'analyzer' parameter in search()

The API Document says that search(*args, **kwargs) has a parameter called analyzer . API文档说search(*args, **kwargs)有一个名为analyzer的参数。 But the following code raises an exception: 但是以下代码引发了一个异常:

RequestError:TransportError(400, 'illegal_argument_exception', 'request [/test-index/content-field/_search] contains unrecognized parameter: [analyzer]') RequestError:TransportError(400,'illegal_argument_exception','request [/ test-index / content-field / _search]包含无法识别的参数:[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. 使用q参数通过查询字符串进行搜索时,仅使用(并接受)该参数。 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 在这个github问题中找到答案: https//github.com/elastic/elasticsearch-py/issues/495

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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