Elasticsearch中的地理位置索引数组

问题描述 投票:0回答:1

以下是我的(样本)弹性搜索数据,其中包含我要索引的一系列地理坐标。

PUT geomap/_doc/1
{
  "geometry": {
    "coordinates": [
      [
        [
          -10.8544921875,
          49.82380908513249
        ],
        [
          -10.8544921875,
          59.478568831926395
        ],
        [
          2.021484375,
          59.478568831926395
        ],
        [
          2.021484375,
          49.82380908513249
        ],
        [
          -10.8544921875,
          49.82380908513249
        ]
      ]
    ]
  }
}

这是我为此创建的elasticsearch映射。

PUT geomap
{
  "mappings": {
    "properties": {
      "geometry": {
        "properties": {
          "coordinates": { "type": "geo_point" }
        }
      }
    }
  }
}

[当我尝试插入数据时,它不起作用。我怀疑这是由于我拥有数组坐标数组。当我将样本数据集更新为单个坐标数组时,它起作用了(如下)。

PUT geomap/_doc/1
{
  "geometry": {
    "coordinates": [
      [
        -10.8544921875,
        49.82380908513249
      ],
      [
        -10.8544921875,
        59.478568831926395
      ],
      [
        2.021484375,
        59.478568831926395
      ],
      [
        2.021484375,
        49.82380908513249
      ],
      [
        -10.8544921875,
        49.82380908513249
      ]
    ]
  }
}

我很高兴知道自己在映射中犯了什么错误,但我没有这样做。

elasticsearch search geopoints elasticsearch-mapping
1个回答
0
投票

我怀疑您的文档是多边形,所以您将要使用geo_shape

geo_shape

也请注意PUT geomap { "mappings": { "properties": { "geometry": { "type": "geo_shape", "strategy": "recursive" } } } } 的“递归”策略(至少在较新的ES版本中)。

support more spatial queries

请注意,如何将coords数组包装到另一个数组中,以符合geojson标准,并添加了PUT geomap/_doc/1 { "geometry": { "coordinates": [ [ [ -10.8544921875, 49.82380908513249 ], [ -10.8544921875, 59.478568831926395 ], [ 2.021484375, 59.478568831926395 ], [ 2.021484375, 49.82380908513249 ], [ -10.8544921875, 49.82380908513249 ] ] ], "type": "polygon" } } 属性。

© www.soinside.com 2019 - 2024. All rights reserved.