# Reindex ES with aliases

**URL:** <https://discuss.elastic.co/t/reindex-es-with-aliases/109245>\
**Category:** Elasticsearch\
**Created:** [November 27, 2017, 3:58pm UTC](https://discuss.elastic.co/t/reindex-es-with-aliases/109245 "2017-11-27T15:58:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natalia\_Kuleniuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/natalia_kuleniuk/32/43727_2.png) [@Natalia\_Kuleniuk](https://discuss.elastic.co/u/Natalia_Kuleniuk)\
**Post date:** [November 27, 2017, 3:58pm UTC](https://discuss.elastic.co/t/reindex-es-with-aliases/109245/1 "2017-11-27T15:58:38Z")

</div>

Question about alises:  
I have ES index with 10 min documents. I need to add new fields and values for each document. I am going to use Scroll Search API to get documents and Bulk API to copy documents into new index [adding new fields while copying]. After reindexing is finished I would like to use aliases to point on my new index.

First, before reindexing, I am going to set “my\_index\_alias” to point to OLD index:  
curl -XPUT 'endpoint/oldindex/\_alias/my\_index\_alias?pretty'  
After reindexing is finished, I am going to switch aliases:  
curl -XPOST ‘endpoint/\_aliases?pretty' -H 'Content-Type: application/json' -d'  
{  
"actions": [  
{ "remove": { "index": “oldindex", "alias": "my\_index\_alias" }},  
{ "add": { "index": “newindex", "alias": "my\_index\_alias" }}  
]  
}  
'

My first question is:  
Is that correct approach?

My second question is:  
I am not understand well switching aliases procedure Is that right, that after perform reindexing and switching aliases, I will be able to access my new index, the same way I access my old index? We using Java API in our program to access ES, so I wondering whether I need to make some code changes or not? Am I understanding right that after reindexing and switching I will be able call “endpoint/OLDINDEX” and get updated data with new field there? Or I need to make code changes and call “endpoint/NEWINDEX” instead? Or I need to make code changes in code to call “endpoint/my\_index\_alias”?? Can I call my alias the same way my old index is called [OLDINDEX]?

And one more question  
In the OLDINDEX I have two types, for example, “typeone” and “typetwo”. I need to perform reindexing and backfill only for “typeone”. Will I be able to access “typetwo” the same way we did it before? Without any code changes?

Why I do need to prefer reindex in new index and dealing with switching aliases, if I can just use BULK API to update existed index’s documents with new fields?

---

<div class="post-metadata">

**Author:** ![mujtabahussain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mujtabahussain/32/17514_2.png) [@mujtabahussain](https://discuss.elastic.co/u/mujtabahussain)\
**Post date:** [November 28, 2017, 6:34am UTC](https://discuss.elastic.co/t/reindex-es-with-aliases/109245/2 "2017-11-28T06:34:35Z")

</div>

Hi Natalia.

Lets say you have an index `X`. You want add a fields and values to to it and end up with an index `Y`.

Before you do that, how do you access the data that is stored in index `X`? If there is an alias called `current-index`, which points to `X`, then yes we can use aliases to approach this issue. Could you please confirm?

Now let's assume you have an existing alias called `current-index` which points to `X` before re-indexing. In which case, in my humble opinion, this approach will work. You reindex `X` into `Y` and then switch the alias using

```bash
curl -XPOST ‘endpoint/_aliases?pretty' -H 'Content-Type: application/json' -d'
{
"actions": [
{ "remove": { "index": “oldindex", "alias": "my_index_alias" }},
{ "add": { "index": “newindex", "alias": "my_index_alias" }}
]
}
'

```

### Second question

Before reindexing, you had an index `X` and an alias `current-index` that pointed to `X`. You could access the data stored in `X` by doing both:

- curl -XGET ENDPOINT/X
- curl -XGET ENDPOINT/current-index

After you reindex, and switch the alias to point to `Y` you will only be able to access the data stored in `X` by doing `curl -XGET ENDPOINT/X` .

If you do `curl -XGET ENDPOINT/current-index`, this will give you the data of `Y` as it now points to the new index.

> [@](#):
>
> if I can just use BULK API to update existed index’s documents with new fields?

That is a very good question. Whats preventing you from updating `X` itself? Adding new fields to a current index is quite easy and doesn't require a reindex. Changing field types usually requires a reindex. If you are only adding fields, you should be OK!

---

<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:** [December 26, 2017, 6:38am UTC](https://discuss.elastic.co/t/reindex-es-with-aliases/109245/3 "2017-12-26T06:38:32Z")

</div>

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