以下是我的(示例)Elastic搜索数据,其中包含我要索引的一系列地理坐标。
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
]
]
}
}
我很高兴知道自己在映射中犯了什么错误,而我却没有这样做。
最佳答案
我怀疑您的文档是多边形,所以您将要使用 geo_shape
代替:
PUT geomap
{
"mappings": {
"properties": {
"geometry": {
"type": "geo_shape",
"strategy": "recursive"
}
}
}
}
注意support more spatial queries的“递归”策略(至少在较新的ES版本中也是如此)。
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"
}
}
请注意,如何将coords数组包装到另一个数组中,以符合geojson标准,并添加了
type: polygon
属性。
关于elasticsearch - Elasticsearch中的地理位置索引数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60968444/