elasticsearch 地理位置查询:geo_distance

说明

指定 圆心坐标点 和 半径,寻找该圆中的点

如下图:给定 圆心坐标点 和 半径,寻找该圆中的点

查询

GET /meituan_v1/_search
{
  "query": {
    "bool": {
      "must": {
        "wildcard": {
          "name": "*面*"
        }
      },
      "filter": {
        "geo_distance": {
          "distance":      "200km", // 半径
          "location": {  // 圆心坐标
            "lat":  77,
            "lon":  35
          }
        }
      }
    }
  }
}

查询结果:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 2.8797545,
    "hits" : [
      {
        "_index" : "meituan_v1",
        "_type" : "_doc",
        "_id" : "vdyP0nsByvoeiV4Prah2",
        "_score" : 2.8797545,
        "_source" : {
          "name" : "兰州拉面红旗街店",
          "location" : {
            "lat" : 78,
            "lon" : 36
          }
        }
      }
    ]
  }
}

原文出处:/show_1IX1rtSKRK6O.html