elasticsearch,

How to restore index with a different name from an Elasticsearch snapshot

Jul 10, 2022 · 1 min read · Post a comment

You may wonder if it’s possible to rename an Elasticsearch index while doing a restore from an Elasticsearch snapshot but keeping the existing index as it is. Let’s see the scenario. I have an index devcoops and have a backup snapshot of it as well. I will restore devcoops index from the snapshot with a different name without touching the existing one.

Prerequisites

  • Elasticsearch
  • sudo privileges

Solution

Step 1. List the snapshot.

GET /_snapshot/devcoops-dev/devcoops-es-2022-07-10

Output:

snapshots" : [ {
    "snapshot" : "devcoops-es-2022-07-10",
    "uuid" : "NKKI6UzoPYWc7iR0KKlW6Y",
    "version_id" : 145738737,
    "version" : "1.2.4",
    "indices" : [ "devcoops", "index-1", "index-2", "index-3", "index-4",
    ...

Step 2. Restore devcoops index with a different name devcoops_backup without touching devcoops and its data.

POST /_snapshot/devcoops-dev/devcoops-es-2022-07-10/_restore
{
  "indices": "devcoops",
  "rename_pattern": "(.+)",
  "rename_replacement": "$1_backup"
}
  • $1: Will take the name of the existing index devcoops.

Step 3. If you list the indexes, you will have both of them in your ES cluster.

GET /_cat/indices

Output:

green  devcoops                        KDLSADSA 1 1  16865      0   6.3mb     5mb
green  devcoops_backup                 DSAKDSAD 1 1   8440   1520  8.8mb   4.8mb

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.