Elasticsearch 查询存在于多个地理位置的值

Elasticsearch query for values that exist in multiple geo locations

我有一个索引,其中包含如下所示的文档:

{
    "name": "some name",
    "location: { "type": "Point", "coordinates": [3.295, 6.673]}
}

我可以进行地理多边形查询,没问题。但现在我想搜索两个地理多边形,并只搜索 return 两个具有相同 "name" 值的文档。因此,如果 "name":"Jason Smith" 存在于两个地理多边形中,那么这些文档将被 returned。但是如果"Jason Smith"只存在一个,那么它就不会被returned。我不知道如何编写此查询,因此将不胜感激任何帮助。

这是我现在正在处理的查询:

{
    "query":{
        "bool":{
            "filter":{
                "bool":{
                    "should":[
                        {"geo_distance": {"coordinates":[32.4809, 12.0422],"distance": "100 m"}},
                        {"geo_distance": {"coordinates":[33.4827, 13.0438],"distance": "100 m"}}
                    ]
                }
            }
        }
    },
    "aggs":{
        "found":{
            "terms":{
                "field": "name"
            }
        }
    }
}

"must" 和 "should" 我都试过了。 Must 将只 return 两个区域中具有 lat/lng 坐标的文档,并且 Should returns 来自两个区域的所有文档。我需要查询 return 个在两个区域中具有相同 "name" 的文档,而不是坐标。

好的,所以我编辑了。我们应该按名称聚合,然后使用请求的 aera 之一按区域聚合。在我们 post 使用 bucket_selector 过滤聚合后, _bucket_count 获取 subaggeo 聚合的数组大小,因此如果他的大小为 == 2,则名称在两个 aera 上。请告诉我它是否有效 ;)

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "should": [
            {
              "geo_distance": {
                "coordinates": {
                  "lat": 48.858837,
                  "lon": 2.27702
                },
                "distance": "10km"
              }
            },
            {
              "geo_distance": {
                "coordinates": {
                  "lat": 40.697149,
                  "lon": -74.2598
                },
                "distance": "10km"
              }
            }
          ]
        }
      }
    }
  },
  "aggs": {
    "found": {
      "terms": {
        "field": "name",
        "min_doc_count": 2
      },
      "aggs": {
        "subagggeo": {
          "geo_distance": {
            "field": "coordinates",
            "origin": "48.858837, 2.27702",
            "unit": "m",
            "ranges": [
              {
                "to": 10000
              },
              {
                "from": 10001
              }
            ]
          }
        },
        "min_bucket_selector": {
      "bucket_selector": {
        "buckets_path": {
          "hits": "subagggeo._bucket_count"
        },
        "script": {
          "inline": "params.hits > 1"
        }
      }
    }
      }
    }
  }
}