【问题标题】:Querying ElasticSearch for all documents with a Geo Point that intersects/within an indexed Geo Shape查询具有与索引地理形状相交/在索引地理形状内的地理点的所有文档的 ElasticSearch
【发布时间】:2017-04-05 01:40:00
【问题描述】:

我有一组从我已索引到 ES 的形状文件中提取的 geo_shapes。我还有大量带有 geo_points 的文档索引。我正在尝试运行一个查询,该查询返回在 geo_shape 中具有一个点的所有文档,但始终返回零结果。

我很确定映射是正确的,因为我可以查询特定的纬度/经度并成功取回它所在的 geo_shape。我还可以使用 geo_points 对文档进行边界框搜索并成功获取匹配的文档列表。

这是我的 geo_shapes 的映射:

{
    "geometry": {
        "properties": {
            "type": "geo_shape",
            "tree": "quadtree"
        }
    }
}

这是带有 geo_points 的文档的映射:

{
    "docs": {
        "location": {
            "properties": {
                "coordinates": {
                    "type": "geo_point",
                    "geohash": true
                }
            }
        }
    }
}

我要运行的查询是:

{
    "query": "geo_shape": {
        "location": {
            "indexed_shape": {
                "id": "shape_id",
                "type": "locations",
                "index": "index_name",
                "path": "geometry"
            }
        }
    }
}

我正在针对包含具有 geo_points 的文档的特定索引/类型运行查询。如果我对整个索引运行它,那么只有 geo_shape 文档返回。

【问题讨论】:

  • "如果我对整个索引运行它,那么只有 geo_shape 文档返回。"您是指针对整个形状索引而不是特定的预索引形状运行吗?如果是,你会怎么做?

标签: elasticsearch elasticsearch-geo-shape


【解决方案1】:

为了使其正常工作,您的第二个索引中的位置也需要映射为 geo_shape (type=Point)(而不是 geo_point),如下所示:

{
  "locations": {
    "location": {
      "properties": {
        "coordinates": {
          "type": "geo_shape",
          "tree": "quadtree",
          "precision": "1m"
        }
      }
    }
  }
}

那么您在pre-indexed shapes 上的geo_shape 查询将按预期工作

【讨论】:

  • 那行不通。我尝试将地理形状映射到“位置”级别和“坐标”级别。此外,如果我这样做,那么它就无法在 geo_point 上进行边界框查询。
  • 好的。我让它工作。我对我在原始帖子中修复的查询感到困惑。
  • @Val,什么是查询多个预索引形状内的点的好方法(例如:查询所有形状内的所有点)?
猜你喜欢
  • 1970-01-01
  • 2017-09-19
  • 1970-01-01
  • 2016-12-28
  • 1970-01-01
  • 2015-03-19
  • 2015-06-23
  • 2020-07-21
  • 2013-12-30
相关资源
最近更新 更多