elasticsearch 弹性搜索范围查询
考虑索引中的两个文档,如下所示:elasticsearch 弹性搜索范围查询,elasticsearch,lucene,elasticsearch,Lucene,考虑索引中的两个文档,如下所示: { "_index": "32", "_type": "places", "_id": "_FqlAzzSRN6Ge_294D5Mwg", "_score": 1, "_source": { "name_3": "xxxx", "id_3": "xxxxx",
{
"_index": "32",
"_type": "places",
"_id": "_FqlAzzSRN6Ge_294D5Mwg",
"_score": 1,
"_source": {
"name_3": "xxxx",
"id_3": "xxxxx",
"name_2": "xxxx",
"id_2": "xxx",
"name_1": "xxx",
"id_1": "xxx",
"tempid": "xxxxx",
"field1": 316.6666666666667,
"type": "processeddata"
}
},
{
"_index": "32",
"_type": "places",
"_id": "3RCO-zHeSr2nWFZd8W-MDg",
"_score": 1,
"_source": {
"name_3": "yyyy",
"id_3": "yyy",
"name_2": "yyy",
"id_2": "yyy",
"name_1": "yyyy",
"id_1": "yyy",
"tempid": "yy",
"field2": 400.6666666666667,
"type": "processeddata"
}
}
我想为以下场景构造一个查询。我必须为特定范围内的字段查找文档
字段1:200-400
字段2:300-400,因此上述两个文档应随附
我的质询如下:
"query": {
"bool": {
"must": [
{
"range": {
"field1": {
"gte": 200,
"lte": 400
}
},"range": {
"field2": {
"gte": 300,
"lte": 400
}
}
}
]
}
}
但上述质疑“在单个文档中查找2个字段,因此没有结果。因此,我必须搜索是否有任何文件满足文档中应返回的范围。请分享你的想法。提前感谢。您需要使用
bool should
而不是bool must
。这意味着匹配至少符合一个条件的任何文档。
注意:您的第二个条件与第二个文档不匹配,因为400.66不在范围[300400]
内