# How to reindex data in Elasticsearch without actually changing index names?

**URL:** <https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034>\
**Category:** Elasticsearch\
**Created:** [October 15, 2017, 6:47pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034 "2017-10-15T18:47:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [October 15, 2017, 6:47pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/1 "2017-10-15T18:47:21Z")

</div>

Hi,

I am trying to reindex data in Elasticsearch without actually changing index names. I am ingesting data to indices based on monthly index names(index-%{+[YYYY.MM](http://YYYY.MM)}). I've seen concept of using aliases, but I am not sure how to create new index. Do I need to create index\_new or index\_new-%{+[YYYY.MM](http://YYYY.MM)}?

Can someone please help me solve the issue?

Thanks

---

<div class="post-metadata">

**Author:** ![Bernt\_Rostad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bernt\_Rostad](https://discuss.elastic.co/u/Bernt_Rostad)\
**Post date:** [October 16, 2017, 8:51am UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/2 "2017-10-16T08:51:40Z")

</div>

You must reindex into a new index so the name must be different from the old index. An alias is a good way to hide the actual index names from the query clients. That way you can create new versions of an index, call the Reindex API to build up the new index and finally point the alias to the new index.

In my company we also do monthly indices and from time to time we need to reindex because of mapping changes. In order to do that we have a simple rule for mapping an alias to an index:

`<alias prefix>_<name>_<yyyy>_<mm>: <index prefix>_<name>_<yyyy>_<mm>_<version>`

The alias prefix is a common text string prepended to all our searchable aliases, it was needed to allow clients to search across all aliases (GET /\<alias prefix\>\*/\_search?q=...) while skipping over the indices (to avoid duplicate results). The index prefix is also a text string but only prepended to our indices and so only known to our internal systems, typically our indexer engine. This allows us to handle multiple versions of indices and easily change aliases without anyone noticing, e.g.:

```
POST /_aliases
{
     "actions" : [
           { "remove" : { "index" : "int_blog_2017_04-v3", "alias" : "pub_blog_2017_04" } },
           { "add" : { "index" : "int_blog_2017_04-v4", "alias" : "pub_blog_2017_04" } }
     ]
}'
```

---

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [October 16, 2017, 2:51pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/3 "2017-10-16T14:51:26Z")

</div>

Hi Bernt. Thanks for your reply.

So right now I have indices with the names "project-2017.08", "project-2017.09", "project-2017.10". In the Kibana end the index looks like "project-\*".

- Do I need to create 3 new indices with the names "sample-project-2017.08\_v1" , "sample-project-2017.09\_v1" , "sample-project-2017.10\_v1" and point alias to the new indices?

- If so, what about the next month's data? I am assuming I need to declare index template with required mapping so that next month's data will be distributed to project-2017.11 without any aliases.

I am totally confused how things work for monthly based indices. Please let me know if this is the correct process.

Thanks for the support

---

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [October 16, 2017, 5:40pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/4 "2017-10-16T17:40:52Z")

</div>

Can someone please help me solve the issue?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 16, 2017, 8:34pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/5 "2017-10-16T20:34:32Z")

</div>

Please read

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

Specifically the "be patient" part.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 16, 2017, 8:45pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/6 "2017-10-16T20:45:01Z")

</div>

You should be able to create a new, updated index template that apply to all indices that starts with the pattern `project-*`. This will apply to all new indices being created, e.g. `project-1017.11`. If you then reindex the content of `project-2017.09` into `project-2017.09-1`, the template will apply here as well. You should then be able to delete the `project-2017.09` index and once this is done create an alias `project-2017.09` that points to `project-2017.09-1`. If you are primarily querying through Kibana, the new index will still match the configured index pattern and you may not even need to create the alias.

---

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [October 16, 2017, 9:07pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/7 "2017-10-16T21:07:39Z")

</div>

I am using Logstash to push data to ES index. Configuration of Logstash would be something like,

```
output {
                elasticsearch {
                        hosts => ["host1","host2","host3"]
                        index => "project-%{+YYYY.MM}"
                }
}

```

Can you please say where would this month's data go if I delete project-2017.10(after reindexing data to project-2017.10-1)?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 16, 2017, 9:09pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/8 "2017-10-16T21:09:43Z")

</div>

If you add the alias, you would still be able to index into this if necessary, and data would end up in the new, linked index.

---

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [October 16, 2017, 9:16pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/9 "2017-10-16T21:16:56Z")

</div>

So for the last 2 months I can just reindex data and delete old indices. But for the present month I will need to add the alias.

```
   curl -XPOST localhost:9200/_aliases -H 'Content-Type: application/json' -d '
    {
        "actions": [
            { "add": {
                "alias": "project-2017.10",
                "index": "project-2017.10-1"
            }}
        ]
    }

```

Please let me know if this is the right approach.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 17, 2017, 2:46am UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/10 "2017-10-17T02:46:54Z")

</div>

I have not tested it, but think it should work.

---

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [October 18, 2017, 1:39pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/11 "2017-10-18T13:39:35Z")

</div>

Thanks a lot Christian. I have reindexed everything. It's working now.

This is fine since I have just 3 indices, what if I have 20 indices? Do I need to repeat the process for all 20 indices and delete old indices?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 18, 2017, 3:56pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/12 "2017-10-18T15:56:36Z")

</div>

Yes, you would need to do it for all indices.

---

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [October 19, 2017, 2:12pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/13 "2017-10-19T14:12:58Z")

</div>

Got it, thanks for your support. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 16, 2017, 2:13pm UTC](https://discuss.elastic.co/t/how-to-reindex-data-in-elasticsearch-without-actually-changing-index-names/104034/14 "2017-11-16T14:13:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
