如何在弹性搜索python中结合这两个查询? [英] How do I combine these two queries in elastic search python?
本文介绍了如何在弹性搜索python中结合这两个查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想结合两个查询
第一个返回的结果具有大于0的"analysis.data_counts"值.
First one returns results that have the "analysis.data_counts" value greater than 0.
{
"query": {
"range" : {
"analysis.data_counts" : {
"gte" : 1,
}
}
}
}
第二个变量查看它是否具有某个字段,并检查另一个字段bool值,如果它具有该值,则会在查询中将其提升为更高的值,以便它们首先出现
The second one sees if it has a certain field and also checks another fields bool value and if it has that value boosts it higher in the query so they appear first
"query": {
"bool": {
"must": {
"exists": {
"field": "data_types"
}
},
"should": {
"term": {
"reviewed": False
},
}
}
}
})
所以我需要将它们绑在一起,以便获得具有"analysis.data_counts"> = 1的结果,字段类型为"data_types"并使"reviewed" == False出现在True之前
So I need to tie them together so I can get results that have "analysis.data_counts" >= 1, have the field type "data_types" and make the "reviewed" == False appear before the True ones
推荐答案
您可以这样做:
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "data_types"
}
},
{
"range" : {
"analysis.data_counts" : {
"gte" : 1,
}
}
}
],
"should": {
"term": {
"reviewed": False
}
}
}
}
}
这篇关于如何在弹性搜索python中结合这两个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文