ElasticSearch地理搜索

时间:2016-07-26 12:23:05

标签: elasticsearch geolocation geospatial

所以我刚开始使用elasticsearch并且在地理搜索方面遇到了一些麻烦。

我有这个索引:

"mappings" => [
    "draw_point" => [
        "properties" => [
            "name" => ["type" => "string"],
            "type" => ["type" => "string"],
            "location" => ["type" => "geo_point"]
        ]
    ]
]

并插入一些数据:

{
    "_index": "draw_points",
    "_type": "draw_point",
    "_id": "AVYnDfCLzY04KlPeX37B",
    "_score": 1,
    "_source": {
      "name": "Tower",
      "type": "Water",
      "location": {
        "lat": 48.8584,
        "lon": 2.2945
      }
    }
  }

然而,当我使用以下内容进行地理搜索时,我总会得到一切:

"query": {
   "filtered": {
    "query": {
        "match_all": {}
    },
    "filter": {
        "geo_distance": {
            "distance": "1km",
            "location": {
            "lat": 51.5074,
            "lon": 0.1278
          }
        }
      }
    }
}

0 个答案:

没有答案