4

API 文档说search(*args, **kwargs)有一个名为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)

但是,以下代码返回正确答案。

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

1 回答 1

1

该参数仅在使用 q 参数通过查询字符串进行搜索时使用(并接受)。在您的情况下,您需要在 body[.] 中为匹配查询指定分析器

在这个 github 问题中找到了答案:https ://github.com/elastic/elasticsearch-py/issues/495

于 2017-05-28T15:00:38.730 回答