使用经纬度精确匹配查找ElasticSearch文档

4

我在我的索引中有这个字段映射:

 "businessLocation": {
            "type": "geo_point"
          },

我希望使用我的 lat/long 坐标精确匹配查找文档。我尝试了 geo_distance,但是要求距离大于0。

我甚至尝试了这个查询:

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "default_field": "businessLocation",
            "query": "src.lat = 34.47  AND src.lon = -122.37"
          }
        }
      ]
    }
  }
}

然而,我遇到了这个错误:
Geo fields do not support exact searching, use dedicated geo queries instead: [businessLocation]
1个回答

4
您需要以不同的方式查询地理字段。这就是错误所述的内容。请参阅 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html 以获取更多信息。
如果您需要符合您标准的结果,考虑降低距离查询的距离参数,但请记得保持坐标精度
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "2km",
                    "businessLocation" : {
                        "lat" : 34.47,
                        "lon" : -122.37
                    }
                }
            }
        }
    }
}

将答案加1,但更重要的是,如果要精确匹配一个点,您可以将距离降至1毫米(“distance”:“1mm”),这基本上是一个精确匹配。 - mike b
谢谢你的+1 :D 你对选项是正确的,但我认为这个低距离只能匹配具有高分辨率(小数位数)的经纬度的文档。 - ibexit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接