我试图将一个字段的映射从text类型更改为geo_point
后重新索引。
源索引中的现有数据如下所示:
"location" : {
"lat_long" : [
"49.266498",
"-122.998938"
],
我如何在
_reindex
api上调用以下失败:"cause": {
"type": "mapper_parsing_exception",
"reason": "failed to parse field [location.lat_long] of type [geo_point]",
"caused_by": {
"type": "parse_exception",
"reason": "unsupported symbol [.] in geohash [49.228065]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "unsupported symbol [.] in geohash [49.228065]"
}
}
},
最佳答案
问题是在您的source_index
中,即latitude.lat_long
字段不符合 geo_point
数据类型支持的有效的四种不同表示形式。
因此,当您尝试重新建立索引时,转换将失败。
唯一适用的字符串表示形式应为以下格式"lat, lon"
,但是您拥有的是[ "lat", "lon" ]
,它不过是字符串数组。
如果表示形式为以下格式,则重新索引将成功执行。
"location" : {
"lat_long" : "49.266498, -122.998938"
]
}
作为解决方案,您可以执行以下步骤:
步骤1:建立Ingest Pipeline
执行以下查询以创建管道,该管道会将
input format
的latitude.lat_long
转换为如上所述的所需格式PUT _ingest/pipeline/my-pipeline-geo
{
"description" : "geo-point pipeline",
"processors" : [
{
"script": {
"lang": "painless",
"source": "ctx.temp = \"\"; for (def item : ctx.location.lat_long) { if(ctx.temp==\"\") { ctx.temp += item } else { ctx.temp = ctx.temp + ', ' + item} }"
}
},
{
"remove": {
"field": "location"
}
},
{
"set": {
"field": "location.lat_long",
"value": "{{temp}}"
}
},
{
"remove": {
"field": "temp"
}
}
]
}
步骤2:执行以下重新索引查询
POST _reindex
{
"source": {
"index": "source_index"
},
"dest": {
"index": "dest_index",
"pipeline": "my-pipeline-geo"
}
}
注意,在重新索引步骤中,我是如何使用步骤1 中创建的管道的。
输出将采用我上面提到的格式。请花点时间阅读一下Elasticsearch中内置的Ingestion API。
测试,验证,让我知道如何进行。
关于elasticsearch - 重新索引失败,数组映射到geo_point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55228591/