首页 > 解决方案 > 如何在弹性搜索中基于多个地理点搜索文档?

问题描述

我有一个用例,我想在其中搜索具有多个地理点的文档。

{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_distance": {
          "distance": "100m",
          "nc_extraData.nc_geoPoint": {
            "lat": 21.36042723377568,
            "lon": -5.646749208228298
          }
        }
      }
    }
  }
} 

此查询仅支持单个地理点。可能吗。

标签: elasticsearch

解决方案


您可以添加多个geo_distance具有不同地理点的约束。您还可以使用命名查询知道哪个点匹配:

{
  "query": {
    "bool": {
      "should": [
        {
          "geo_distance": {
            "distance": "100m",
            "nc_extraData.nc_geoPoint": {
              "lat": 21.36042723377568,
              "lon": -5.646749208228298
            },
            "_name": "point 1"
          }
        },
        {
          "geo_distance": {
            "distance": "100m",
            "nc_extraData.nc_geoPoint": {
              "lat": 22.36042723377568,
              "lon": -6.646749208228298
            },
            "_name": "point 2"
          }
        },
        {
          "geo_distance": {
            "distance": "100m",
            "nc_extraData.nc_geoPoint": {
              "lat": 23.36042723377568,
              "lon": -7.646749208228298
            },
            "_name": "point 3"
          }
        }
      ]
    }
  }
}

推荐阅读