How to perform 'Delete I1 -> Create I2 -> Switch Alias To I2' in a Synchronous blocking way


My requirement is to create an index and insert some records in it.
However, before I can create the index, I need to check whether an old index of this name exists and delete it, if it does, since it may contain older mappings.

To do this, below are the steps that I am performing:

1.] if exists(old_I)

2.] create (new_I);

3.] ensureYellow(new_I);

4.] alias(remove I->old_I; add I->new_I);

5.] Index some records using I;

My question is whether this is deterministic in its behavior to always run in the same consistent manner?

Because of the way in which ElasticSearch APIs return the Acknowledgement, asynchronously, but operations may not have completed fully on every node.

Since I do not understand the internal architecture of the Cluster Pending Tasks, how stuff is merged from multiple masters and ordered? Do create, delete have a different priority than Aliases? Do 'Search' operations have a different queue?

It would be good to know the logical set of steps that would happen on this set of instructions. Also, it would be nice to understand some internals or best practices on task distribution and serialization.


Depends what version you are on, from 2.X this stuff is done synchronously.