【问题标题】:Wrong elasticsearch geo location query错误的elasticsearch地理位置查询
【发布时间】:2016-04-21 21:25:30
【问题描述】:

映射为:

"mappings": {
     "gyms": {
        "properties": {
           "location": {
              "type": "geo_point"
           },
           "name": {
              "type": "string"
           }
        }
     }
  }

我正在尝试检索距给定纬度、经度 10 公里处的所有健身房。 我正在使用这个查询:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "geo_distance": {
          "distance": 10,
          "distance_unit": "km",
          "location": {
            "lat": 41.3819756,
            "lon": 2.17
          }
        }
      }
    }
  }
}

但是出了点问题,因为我在指定的纬度附近有一些健身房,并且弹性搜索响应没有文档。 会发生什么?

更新 查询:

"query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "geo_distance": {
          "distance": "10km",
          "location": {
            "lat":   41.3819756,
            "lon": 2.17
          }
        }
      }
    }
  }

按预期工作!

作为应该出现的文档示例:

{
        "_index": "g4l",
        "_type": "gyms",
        "_score": 1,
        "_source": {
           "gymName": "sds",
           "location": {
              "lat": 41.3994375,
              "lon": 2.16152349999993
           }
        }
     },
     {
        "_index": "g4l",
        "_type": "gyms",
        "_score": 1,
        "_source": {
           "gymName": "sdf",
           "location": {
              "lat": 41.4040134,
              "lon": 2.201350400000024
           }
        }
     }

【问题讨论】:

  • 你能举一个你认为在远处的有索引的健身房的例子吗(不要凭记忆,而是直接从索引中复制)?
  • 为我工作。这是什么版本的ES?
  • 1.6.0 似乎使用米而不是公里进行搜索

标签: elasticsearch geopoints


【解决方案1】:
  • 在查询中过滤器部分从 "location" 更改为 "gyms.location"
  • 这应该适合你。

【讨论】:

    猜你喜欢
    • 2019-05-08
    • 1970-01-01
    • 2014-07-02
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 2013-05-27
    相关资源
    最近更新 更多