python - search() 中的 Elasticsearch-py 无法识别 'analyzer' 参数

标签 python elasticsearch-plugin query-analyzer

API 文档说 search(*args, **kwargs) 有一个名为 analyzer 的参数。但是下面的代码引发了一个异常:

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)

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

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[.]

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

关于python - search() 中的 Elasticsearch-py 无法识别 'analyzer' 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40798042/

相关文章:

python - 比较两个不同大小的数据框中的每个元素并在 Pandas 中添加或删除单词

python - Python 中的 sql (MonetDB) 命令停止

node.js - 为什么 ElasticSearch 匹配查询返回所有结果?

sql-server-2008 - 为什么Sql Server建议在索引已经存在的情况下创建索引?

python - 忽略Python中的 future 日期

python - 使用 Python 和 XenAPI 模块列出 XenCenter list

rss - 在关系数据库之前将记录放入 Elasticsearch 索引

json - 如果在索引已经运行时运行 ElasticSearch 索引会发生什么?

django - 如何在仅具有 DRF 端点的服务器上分析 Django ORM 查询性能?

elasticsearch - 弹性:用不必要的词搜索