gpt4 book ai didi

python - 在 python 中将 Elasticsearch 查询转换为 Elasticsearch-dsl

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:17 26 4
gpt4 key购买 nike

这是一个简单有效的 Elasticsearch 查询。我必须使用 Elasticsearch dsl 模块将其转换为 python 代码。

 GET indexforproject/project/_search
{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"term": {
"project_language.languageName.raw": "nodejs"
}
}
}
}
}

这是我用过的

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search,Q,query,F
client = Elasticsearch([{'host':'blrkec248770d','port':'9200'}])
temp="Internal"
s=Search(using=client, index="indexforproject").filter("term","project_language.languageName.raw"="Internal")
body={
'query':"PHP and node.js",
'filters':[{'name':"languages",'values':"[python,PHP,angular]"} ]
}


response=s.execute()
for hit in response:
print hit.title

最佳答案

我终于明白了。下面是代码:

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search,Q,query,F
client = Elasticsearch([{'host':'blrkec248770d','port':'9200'}])
d={'project_language.languageName.raw':'nodejs'}
s=Search(using=client, index="indexforproject").filter('term',**d)
body={
'query':"PHP and node.js",
'filters':[{'name':"languages",'values':"[python,PHP,angular]"} ]
}

#print s.to_dict()
response=s.execute()
for hit in response:
print hit.title

关于python - 在 python 中将 Elasticsearch 查询转换为 Elasticsearch-dsl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34179142/

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