Elasticsearch映射-重命名现有字段 [英] Elasticsearch Mapping - Rename existing field
问题描述
无论如何,是否可以在现有的Elasticsearch映射中重命名一个元素而不必添加新元素?
如果是这样,为了避免破坏现有的映射,最好的方法是什么?
Is there anyway I can rename an element in an existing elasticsearch mapping without having to add a new element ? If so whats the best way to do it in order to avoid breaking the existing mapping?
例如从fieldCamelcase到fieldCamelCase
e.g. from fieldCamelcase to fieldCamelCase
{
"myType": {
"properties": {
"timestamp": {
"type": "date",
"format": "date_optional_time"
},
"fieldCamelcase": {
"type": "string",
"index": "not_analyzed"
},
"field_test": {
"type": "double"
}
}
}
}
推荐答案
您可以通过创建摄取管道,其中包含重命名处理器与重新索引API 。
You could do this by creating an Ingest pipeline, that contains a Rename Processor in combination with the Reindex API.
PUT _ingest/pipeline/my_rename_pipeline
{
"description" : "describe pipeline",
"processors" : [
{
"rename": {
"field": "fieldCamelcase",
"target_field": "fieldCamelCase"
}
}
]
}
POST _reindex
{
"source": {
"index": "source"
},
"dest": {
"index": "dest",
"pipeline": "my_rename_pipeline"
}
}
请注意,您需要运行Elasticsearch 5.x才能使用摄取。如果您正在跑步< 5.x,则必须使用@Val在他的评论中提到的内容:)
Note that you need to be running Elasticsearch 5.x in order to use ingest. If you're running < 5.x then you'll have to go with what @Val mentioned in his comment :)
这篇关于Elasticsearch映射-重命名现有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!