Elasticsearch Mapping - Rename existing field

旧时模样 提交于 2019-12-03 15:52:05

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"
  }
} 

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 :)

First of all, you must understand how elasticsearch and lucene store data, by immutable segments (you can read about easily on Internet).

So, any solution will remove/create documents and change mapping or create a new index so a new mapping as well.

The easiest way is to use the update by query API: https://www.elastic.co/guide/en/elasticsearch/reference/2.4/docs-update-by-query.html

POST /XXXX/_update_by_query

{
    "query": { 
    "missing": {
      "field": "fieldCamelCase"
    }
  },
    "script" : {
        "inline": "ctx._source.fieldCamelCase = ctx._source.fieldCamelcase; ctx._source.remove(\"fieldCamelcase\");"
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!