错误的elasticsearch地理位置查询

时间:2015-06-28 19:23:22

标签: elasticsearch geopoints

映射为:

"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
          }
        }
      }
    }
  }
}

但有些事情是错误的,因为我在lat lon附近有一些健身房,而elasticsearch响应没有文件。 可能会发生什么?

更新 查询:

"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
           }
        }
     }

1 个答案:

答案 0 :(得分:0)

  • 在过滤器部分的查询更改中,从"位置" " gyms.location"
  • 这应该适合你。