我的一些文档有一个具有结构的字段geo_point:
{
"geoLocation" : [
45.32,
33.33
]
}其中一些是有结构的:
{
"geoLocation" : {
"lat" : 22.22,
"lon" : 66.66
}
}有什么方法可以找到第一个结构的所有结果吗?我想统一"geoLocation“字段。
谢谢!
发布于 2020-07-02 06:29:53
如果您想统一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 ];
}
"""
}
}https://stackoverflow.com/questions/62689356
复制相似问题