gpt4 book ai didi

python - 我如何建立Dynamicx查询elasticsearch_dsl python

转载 作者:行者123 更新时间:2023-12-02 22:31:52 25 4
gpt4 key购买 nike

我在elasticsearch_dsl python库中存在以下问题。

我正在开发具有搜索功能的Web应用程序(DJANGO框架)。我想建立一个动态查询,必须模式。

所以这是下面的代码

i = 0
must = []
while (i < len(results['words'])):
must.append(Q('match', tags=results['words'][i]))
i += 1

print must
client = Elasticsearch()
es = Search(using=client, index="_______")
es.query(must)
response = es.execute()
for hit in response:
print hit
return response.hits.total

Python返回exceptions.TypeError

我已经有elasticsearch_dsl的文档,但是找不到类似我的问题的文档。您知道我如何解决此问题的方式吗?

最佳答案

你有点亲密。您需要指定bool,然后像这样查询Search对象

i = 0
must = []
while (i < len(results['words'])):
must.append(Q('match', tags=results['words'][i]))
i += 1

print must
client = Elasticsearch()
q = Q('bool', must=must) <--- This is important
es = Search(using=client, index="_______").query(q)
response = es.execute()
for hit in response:
print hit
return response.hits.total

您还可以使用 es.to_dict()查看实际查询,这可以帮助您了解

关于python - 我如何建立Dynamicx查询elasticsearch_dsl python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34712303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com