gpt4 book ai didi

elasticsearch - Elasticsearch查询geo_point结构

转载 作者:行者123 更新时间:2023-12-03 01:15:35 25 4
gpt4 key购买 nike

我的一些文档的geo_point字段具有以下结构:

{
"geoLocation" : [
45.32,
33.33
]
}
其中一些具有结构:
{
"geoLocation" : {
"lat" : 22.22,
"lon" : 66.66
}
}
有没有办法找到提到的第一个结构的所有结果?我想统一“geoLocation”字段。
谢谢!

最佳答案

如果要统一geoLocation字段,您可以通过在所有文档上查询来运行更新,而仅更新其中一部分。下面将所有geoLocation数组更新为lat/lon对象版本。

POST test/_update_by_query
{
"script": {
"source": """
if (ctx._source.geoLocation instanceof ArrayList) {
ctx._source.geoLocation = [
"lat": ctx._source.geoLocation[1],
"lon": ctx._source.geoLocation[0]
];
}
"""
}
}
如果要以其他方式(从对象到数组)进行更新,则可以这样进行:
POST test/_update_by_query
{
"script": {
"source": """
if (ctx._source.geoLocation instanceof Map) {
ctx._source.geoLocation = [ ctx._source.geoLocation.lon, ctx._source.geoLocation.lat ];
}
"""
}
}

关于elasticsearch - Elasticsearch查询geo_point结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62689356/

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