ElasticSearch查询未给出正确结果

f45qwnt8  于 2023-03-01  发布在  ElasticSearch
关注(0)|答案(1)|浏览(150)

我有一个ElasticSearch查询查询是

GET /My_Index_Name/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "geo_distance": {
            "addresses.location.longitudeLatitude": {
              "lat": "57.7092",
              "lon": "11.9816"
            },
            "distance": "2000km"
          }
        }
      ]
    }
  }
}

这是字段“经度-纬度”的Map:{“类型”:“地理点”}
正确的结果是指,我有候选项的数据,并且存储了候选项的纬度和经度,因此,当我运行此查询时,我希望显示这些候选项记录

kx5bkwkv

kx5bkwkv1#

通过坐标按距离获取数据:

以下是更新后的查询

GET /My_Index_Name/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}   //Added a match_all clause to retrieve all documents in the index
        },
        {
          "geo_distance": {
            "distance": "2000km",
            "addresses.location.longitudeLatitude": {
              "lat": 57.7092,
              "lon": 11.9816
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "_geo_distance": {   //Added a sort parameter to sort results by distance
        "addresses.location.longitudeLatitude": {
          "lat": 57.7092,
          "lon": 11.9816
        },
        "order": "asc",
        "unit": "km",
        "distance_type": "plane"
      }
    }
  ]
}

相关问题