Starting from Elasticsearch 7.4, the best way to rename indices is to use the newly introduced clone index API to clone the index and then use the delete index API to remove the original index.
Compared to using the snapshot API or reindex API for the same purpose, the main advantage of the clone index API is speed, because it hard-links segments from the source index to the target index without reprocessing any content. On systems that support hard links, this is efficient; otherwise, files are copied at the filesystem level, which is still more efficient than alternatives. The clone index operation also guarantees that the target index is identical to the source index at every point (i.e., no manual copying of settings and mappings is required, unlike the reindex method), and it does not require configuring a local snapshot directory.
Note: Although this process is significantly faster than previous solutions, it still involves downtime. There are practical use cases where renaming indices is justified (e.g., as part of a splitting, shrinking, or backup workflow), but renaming indices should not be part of routine operations. If your workflow requires frequent index renaming, consider using index aliases.
The following is a complete sequence of operations to rename an index from source_index to target_index. It can be executed using some Elasticsearch-specific consoles, such as the console integrated in Kibana. See this gist for an alternative version using curl instead of the Elasticsearch console.
# Make sure the source index is actually open
POST /source_index/_open
# Put the source index in read-only mode
PUT /source_index/_settings
{
"settings": {
"index.blocks.write": "true"
}
}
# Clone the source index to the target name, and set the target to read-write mode
POST /source_index/_clone/target_index
{
"settings": {
"index.blocks.write": null
}
}
# Wait until the target index is green;
# it should usually be fast (assuming your filesystem supports hard links).
GET /_cluster/health/target_index?wait_for_status=green&timeout=30s
# If it appears to be taking too much time for the cluster to get back to green,
# the following requests might help you identify eventual outstanding issues (if any)
GET /_cat/indices/target_index
GET /_cat/recovery/target_index
GET /_cluster/allocation/explain
# Delete the source index
DELETE /source_index