在Elasticsearch中将FeatureCollection转换为geo_shape [英] FeatureCollection to geo_shape in Elasticsearch

查看:128
本文介绍了在Elasticsearch中将FeatureCollection转换为geo_shape的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FeatureCollection看起来像这样:

I have a FeatureCollection looking like this:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[1.96, 42.455],[1.985,42.445]]]
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [...]
      }
    }
  ]
}

如何将其翻译为es geo_shape .目前,我只是像这样对其进行索引(删除 type:Feature type:FeatureCollection 字段)并添加一个映射:

How can I translate this into the es geo_shape. Currently I just index it like that (dropping type: Feature and type: FeatureCollection fields) and add a mapping saying:

"features": {
    "geometry": {
      "type": "geo_shape"
    }
}

这似乎很好用,但是由于我给出了一个 geometry s数组,所以感觉不对.可以吗?还是正确的方法是将 FeatureCollection 转换为 geometrycollection ?显然需要多个 geometry 元素.

This seems to work fine, but feels wrong, as I give an array of geometrys. Is this okay or would the right way be to translate the FeatureCollection to type geometrycollection? Which clearly wants multiple geometry elements.

一个后续问题,我可以对一个查询进行查询吗:在一个查询中给我几何上所有包含在元素X内的元素(其中X也在索引中),而无需获取X且要执行多个跟进每个多边形的查询?

One Followup question, can I do a query a la: Give me all elements geometrically inside Element X(where X is also in the index) in one query, without fetching X and than doing multiple follow up queries for each polygon?

推荐答案

所以,如果您有这个:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [[[1.96, 42.455],[1.985,42.445]]]
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [...]
      }
    }
  ]
}

您可以像这样在ES中对其进行索引:

You can index it in ES like this:

PUT example
{
  "mappings": {
    "doc": {
      "properties": {
        "location": {
          "type": "geo_shape"
        }
      }
    }
  }
}

POST /example/doc
{
    "location" : {
        "type": "geometrycollection",
        "geometries": [
            {
                "type": "Polygon",
                "coordinates": [[[1.96, 42.455],[1.985,42.445]]]
            },
            {
                "type": "Polygon",
                "coordinates": [...]
            }
        ]
    }
}

因此,基本上,您只需要:

So basically, you simply need to:

  • FeatureCollection 更改为 geometrycollection
  • 功能更改为几何形状
  • 使用 geometry 内部对象
  • 填充 geometries 数组
  • change FeatureCollection to geometrycollection
  • change features to geometries
  • populate the geometries array with the geometry inner-objects

关于您的查询,您可以这样做:

Regarding your query, you can do it like this:

POST /example/_search
{
    "query":{
        "bool": {
            "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "envelope",
                            "coordinates" : [[13.0, 53.0], [14.0, 52.0]]
                        },
                        "relation": "within"
                    }
                }
            }
        }
    }
}

in 之间的关系将返回其 geo_shape 字段在查询中指定的几何范围内的所有文档.

The within relationship returns all documents whose geo_shape field is within the geometry given in the query.

这篇关于在Elasticsearch中将FeatureCollection转换为geo_shape的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆