Reindex ES with aliases

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?

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

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.

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!

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