这是我们的文档:
{
"geometry" : {
"type" : "Point",
"coordinates" : [ -87.662682, 41.843014 ]
}
}
我们想对
geo_shape
字段进行_geo_distance
排序的geometry
搜索。前者需要geo_shape
类型,而后者则需要geo_point
。这两个索引分别成功,但不能一起成功:
"geometry": {
"type": "geo_shape"
}
和
"geometry": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
},
到目前为止,我们已经尝试了这些,但失败:
"geometry": {
"type": "geo_shape"
},
"geometry.coordinates": {
"type": "geo_point"
},
还
"geometry": {
"copy_to": "geometryShape",
"type": "geo_shape"
},
"geometryShape": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
还
"geometry": {
"copy_to": "geometryShape",
"properties": {
"coordinates": {
"type": "geo_point"
}
}
},
"geometryShape": {
"type": "geo_shape"
}
关于如何正确创建此索引的任何想法?
最佳答案
如果启用了脚本,则可以通过在映射中指定transforms来实现
在这些行上看起来会有些变化:
put test/test_type/_mapping
{
"transform": {
"script": "if (ctx._source['geometry']['coordinates']) ctx._source['test'] = ctx._source['geometry']['coordinates']",
"lang": "groovy"
},
"properties": {
"geometry": {
"type": "geo_shape"
},
"coordinates": {
"type": "geo_point"
}
}
}
关于elasticsearch - 如何同时使用Elasticsearch的geo_point和geo_shape类型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29855726/