Elasticsearch Elasticsearch Rename Index

By Opster Team

Updated: Jun 7, 2023

| 2 min read

Elasticsearch: Renaming an Index

Renaming an index in Elasticsearch is not a direct operation, but it can be achieved using a two-step process involving reindexing and deleting the original index. This article will guide you through the process of renaming an index in Elasticsearch. If you want to learn how to create, list, query, and delete indices, check out this guide.  

How to Rename an Elasticsearch Index

Step 1: Reindex the Original Index

Reindexing is the process of copying data from one index to another. To rename an index, you’ll need to create a new index with the desired name and reindex the data from the original index. Use the Reindex API to perform this operation:

POST /_reindex
{
"source": {
"index": "old_index_name"
},
"dest": {
"index": "new_index_name"
}
}

Replace `old_index_name` with the name of the index you want to rename, and `new_index_name` with the desired new name for the index.

Step 2: Delete the Original Index

After reindexing is complete and you have verified that the new index contains the correct data, you can delete the original index using the Delete Index API:

DELETE /old_index_name

Replace `old_index_name` with the name of the index you want to delete.

Considerations:

1. Aliases: If you have aliases pointing to the original index, update them to point to the new index. You can use the Update Aliases API to perform this operation:

POST /_aliases
{
"actions": [
{
"remove": {
"index": "old_index_name",
"alias": "alias_name"
}
},
{
"add": {
"index": "new_index_name",
"alias": "alias_name"
}
}
]
}

Replace `old_index_name`, `new_index_name`, and `alias_name` with the appropriate values.

2. Downtime: The reindexing process may take some time, depending on the size of the index and the resources available. During this time, the original index will still be available for search and indexing operations. However, any changes made to the original index after starting the reindexing process will not be reflected in the new index.

3. Reindexing options: The Reindex API offers additional options, such as using a script to modify documents during reindexing or controlling the number of documents processed per batch. Refer to the Elasticsearch documentation for more information on these options.

Conclusion 

By following these steps, you can effectively rename an index in Elasticsearch. Remember to verify the data in the new index and update any aliases before deleting the original index.

How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?