Elasticsearch过滤器增加而不是减少结果



我正在尝试构建以下过滤器逻辑:

at least one geolocation must be truthy
AND
The status must be equal to 1.

现在,当我添加状态查询这一术语时,结果的数量会增加,正如预期的那样。我正在使用的示例索引中的所有记录的状态都等于1。

GET /my-index/_search
{
"query":{
"bool":{
"filter":{
"bool":{
"must":[
{
"term":{
"status": "1"
}
}
],
"should":[
{
"geo_distance":{
"distance":"24km",
"locations":{
"lat":11.11,
"lon":13.52
}
}
},
{
"geo_distance":{
"distance":"24km",
"locations":{
"lat":81.11,
"lon":43.52
}
}
}
]
}
}
}
}
}

U可以做两件事。

过滤器+应该(我会选择(

{
"query": {
"bool": {
"filter": [
{
"term": {
"status": "1"
}
}
],
"should": [
{
"geo_distance": {
"distance": "24km",
"locations": {
"lat": 11.11,
"lon": 13.52
}
}
},
{
"geo_distance": {
"distance": "24km",
"locations": {
"lat": 81.11,
"lon": 43.52
}
}
}
]
}
}
}

使用minimum_should_match

{
"query": {
"bool": {
"must": [
{
"term": {
"status": "1"
}
}
],
"minimum_should_match": 1,
"should": [
{
"geo_distance": {
"distance": "24km",
"locations": {
"lat": 11.11,
"lon": 13.52
}
}
},
{
"geo_distance": {
"distance": "24km",
"locations": {
"lat": 81.11,
"lon": 43.52
}
}
}
]
}
}
}

最新更新