gpt4 book ai didi

elasticsearch - 如何同时使用 Elasticsearch 的 geo_point 和 geo_shape 类型?

转载 作者:行者123 更新时间:2023-11-29 02:48:22 25 4
gpt4 key购买 nike

这是我们的文档:

{
"geometry" : {
"type" : "Point",
"coordinates" : [ -87.662682, 41.843014 ]
}
}

我们想要使用 _geo_distance 排序进行 geo_shape 搜索,两者都针对相同的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com