Elastic Search

Elasticsearch Rename Index

An Elasticsearch index or indices is (are) a data structure that contains mappings for various documents. In a relational database, an index could refer to a specific database.

An Elasticsearch cluster contains several indices, including multiple types, which then hold the documents.

The following could represent the Elasticsearch relationship with a relational database.

  • PostgreSQL -> Database -> Table ->Row/Column
  • Elasticsearch -> Index -> Type -> Document

In this guide, we will discuss various methods to rename an existing Elasticsearch index.

Method 1: Reindexing

The first method we can use when renaming an index is the reindexing API. This API allows you to copy documents from a source index to a specified destination index.

However, the reindex API does not copy the configuration of the source index to the destination. Hence, we have to set up the destination index and apply the configuration of the source index before calling reindex.

We can implement a full re-index operation by following the steps as outlined below:

  1. Create a new (source) Elasticsearch index
  2. Fetch the configuration of the index and save it.
  3. Create a new (destination) index with the configuration of the source index.
  4. Call the reindex API from source to destination
  5. Delete the source index.

If you have an existing Elasticsearch index, feel free to jump to step 2

NOTE: In this guide, we will provide all the Elasticsearch requests for cURL.

Step 1: Create a new Index
Let us create an index that will act as the source. For simplicity, we will use a simple index configuration with most of the default parameters.

We will tender a request to the Elasticsearch HTTP endpoint.

An example request to create an index “test-index” is below:

curl -XPUT "http://localhost:9200/test-index" -H 'Content-Type: application/json' -d'
  "settings": {
    "index": {
      "number_of_shards": 3,  
      "number_of_replicas": 2
    "mappings": {
    "properties": {
      "field1": { "type": "text" }

The next step is to add data to the created index. By default, the index does not contain any documents.

curl -XGET http://localhost:9200/_cat/indices/test-index\?v

To add data to the index, run the request as:

The request above should create a document in the test-index index.

We can verify the document exists using the GET request to the index endpoint.

curl -XGET "http://locahost:9200/test-index/_search" -H 'Content-Type: application/json' -d'
  "query": {"match_all": {}}

An example output is ans shown:

Step 2: Fetch source configuration
The next step before performing a reindex operation is to copy the configuration of the source index.

We will start by getting the index setting. To do this, we send a HTTP GET request to the _setting API.

settings=$(curl -XGET "https://localhost:9200/test-index/_settings")

We save the output to a variable which we can verify using the command:

echo $settings | jq

Since the output is in JSON format, we pass it to a JSON processor such as jq. An example output is as shown:

The next step is to get the mapping of the index. In this case, we will send a GET request to the _mapping endpoint as:

mapping=$(curl -XGET "https://localhost:9200/test-index/_mapping")

Verify the output is saved to the variable:

echo $mapping | jq

Output is as shown:

Next, combine the output of both $setting and $mapping to a single JSON format.

The following is a truncated screenshot of both combined outputs (config.json).

Step 3: Create a new index
It is now time to create a new index with the save configuration. Ensure your configuration does not contain any errors.

Run the command as:

curl -XPUT "http://localhost:9200 /renamed-index" -H 'Content-Type: application/json' -d config.json'

The following is the content in the config,json file used in this tutorial.

Upon successful creation, you should see acknowledged: true as shown:

Step 4: Reindex
Now that we have a renamed index similar to the source index, we can copy data from the source to destination using the reindex API.

curl -XPOST "http://localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
  "source": {
    "index": "test-index"
  "dest": {
    "index": "renamed-index"

Once you make the reindex request, Elasticsearch will copy the data from the specified source index to the destination index.

Here is an example output:

Step 5: Delete Source Index
It does not make sense to have two indices with similar configuration and data. Hence,  we can drop the source index:

curl -XDELETE http://localhost:9200/test-index
  "acknowledged" : true

Method 2: Clone API

The second and easiest way to rename and index is to use the clone API introduced in Elasticsearch version 7.4 and above.

To use the clone API, you must ensure that the source index is read-only and the cluster health is green.

How Cloning Works
Cloning works as follows:

  • Create a new Elasticsearch index. The new index should contain identical definitions as the old index (source index).
  • The next step is to perform a hard-link segment of the source index to the new Elasticsearch index.
  • Once the hard-link is performed, the new index is re-opened with the definitions and data of the old index.

Step 1: Set source index to read-only
To set the source index to read-only mode, we use the _settings API and pass the info as shown in the request below:

curl -XPUT "http://localhost:9200/test-index/_settings" -H 'Content-Type: application/json' -d'
  "settings": {
    "index.blocks.write": true

Step 2: Clone source index to the target
To clone the test-index to a new index called renamed-cloned-index, we can run the request as shown:

curl -XPOST “http://localhost:9200/test-index/_clone/renamed-cloned-index

Assuming the following requirements are true, you should have a renamed index of the source index.

  1. The specified target index must not exist.
  2. The node has sufficient space to store the cloned index
  3. The source index has an equal number of primary shards as the specified target index.


In this guide, we covered how to rename an Elasticsearch index using two methods.

Thank you for reading!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list