【问题标题】:Find documents by geodistance filter on geoshape field of type Point in ElasticSearch在 ElasticSearch 中点类型的 geoshape 字段上通过地理距离过滤器查找文档
【发布时间】:2016-02-05 23:18:43
【问题描述】:

我的文档在包含位置的弹性搜索中。它们在文档中包含一个名为 location 的字段,其映射为:"location": {"type": "geo_shape"}。我在文档中索引了城市和国家/地区。

在城市类型文档中(由字段"location_type": "city" 标识),位置字段如下所示:"location": {"type": "Point", "coordinates": [12.343, 43.454]}

在国家类型文档中,(由字段"location_type": "country" 标识),位置字段如下所示:"location": {"type": "MultiPolygon", "coordinates": [[12.343, 43.454], [12.23, 34.231]...]}。 我的问题是,我可以像这样运行 geo_distance 过滤器查询吗:

{
  "query": {
    "filtered": {
      "query": {
        "term": {
          "location_type": {
            "value": "city"
          }
        }
      }, 
      "filter": {
        "geo_distance": {
          "distance": 100,
          "distance_unit": "km",
          "location.coordinates": {
            "lat": 40.73,
            "lon": -74.1
          }
        }
      }
    }
  }
}

这给了我一个错误,说:nested: QueryParsingException failed to find geo_point field [location.coordinates]

我怎样才能使这个查询工作?

【问题讨论】:

    标签: elasticsearch geospatial


    【解决方案1】:

    我使用了这种方法。写在这里供其他人参考。

    {
      "query": {
        "geo_shape": {
          "location": {
            "shape": {
              "type": "circle",
              "radius": "100km",
              "coordinates": [ 
                86,
                27
              ]
            }
          }
        }
      }
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-30
      • 2023-03-04
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多