Elasticsearch Mapping - Rename existing field

e.f.a. picture e.f.a. · Mar 30, 2017 · Viewed 19.6k times · Source

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?

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

Answer

Byron Voorbach picture Byron Voorbach · Mar 31, 2017

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