How to Rename Fields when reindexing

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser): 3.1

How does one rename the fields when performing a reindex operation? The application I work on had a major naming convention overhaul and this includes renaming the index fields.

I checked Reindex data - OpenSearch Documentation - Transform documents during reindexing that states that either a script or a ingest pipeline can be used to transform data during a reindex operation but the only straightfoward way I found for renaming was using a search pipeline

Is it possible to rename with ingest pipeline? If so, examples would be welcome

Is it possible to use a search pipeline in the reindex operation? How would it be done?

Is there another way to handling this operation? I would appreciate suggestions.

The renaming is not the only reason for the reindex, as we would also be splitting a larger index on smaller ones and changing some field types.

Thanks in advance!

@sousu You would need to use a pipeline similar to the following:

  1. Create the pipeline
PUT _ingest/pipeline/rename_fields
{
  "processors": [
    { "rename": { "field": "original_field_name", "target_field": "new_field_name", "ignore_missing": true } }
  ]
}
  1. Create the mappings for the new index:
PUT my-new-index
{
  "mappings": {
    "properties": {
      "new_field_name": { "type": "keyword" }
    }
  }
}
  1. Reindex using the pipeline:
POST _reindex?wait_for_completion=true&refresh=true
{
  "source": { "index": "my-index" },
  "dest": {
    "index": "my-new-index",
    "op_type": "create",
    "pipeline": "rename_fields"
  }
}

Hope this helps

1 Like

oh! I missed the rename processor. thanks!