ES 根据地理坐标查询 按照距离从近到远排序

基于地理位置的查询;
朝外soho 39.920086,116.454182
查询距离朝外soho 5km范围内的
上面query是查询条件
下面post_filter对查询结果过滤,按照地理位置过滤/

GET twitter/_search
{
  "query":{
    "bool":{
      "must":[
        {
          "match":{
            "address":"北京"
          }
        }
      ]
    }
  },
  "post_filter": {
    "geo_distance": {
      "distance": "5km",
      "location": {
        "lat": 39.920086,
        "lon": 116.454182
      }
    }
  }
}

查询距离朝外soho 5km范围内的 按距离排序/

GET twitter/_search
{
  "query":{
    "bool":{
      "must":[
        {
          "match":{
            "address":"北京"
          }
        }
      ]
    }
  },
  "post_filter": {
    "geo_distance": {
      "distance": "5km",
      "location": {
        "lat": 39.920086,
        "lon": 116.454182
      }
    }
  },
  "sort": [
    {
      "_geo_distance": {
        "location": {
          "lat": 39.920086,
          "lon": 116.454182
        }, 
        "order": "asc",
        "unit": "km"
      }
    }
  ]
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注