Chan15
Chan15

Reputation: 1009

What is the use of maintaining two aliases for a single Elastic Search Index

I have been exploring Elastic Search lately.

I have been going through aliases. I see ES provides an API to create multiple aliases to a single index like below:

{ "actions" : [{ "add" : { "indices" : ["test1", "test2"], "alias" : "alias1" } }] }

Refer: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#indices-aliases

I'm wondering what is the use case of this.

Won't the queries on aliases get split if an alias point to multiple indices?

I have tried getting the info, but failed to do so as everywhere it's being explained how to acheive this but not the use case.

Directing me to a resource where I could get more info would also help.

Upvotes: 1

Views: 3435

Answers (2)

chai
chai

Reputation: 186

Lets say that you have to types of events, eventA & eventB. You want to "partition" them by time, so you use alias to map multiple indices (e.g. eventA-20220920) to one alias ('eventA' in this case). And you want make one alias for all the event types, so you need to give all the eventA-* and eventB-* indices another alias 'event'.

That way when you add a third type of event (eventC) you can just add them to the 'event' alias and don't change your queries

Upvotes: 0

TechnocratSid
TechnocratSid

Reputation: 2415

A possible use case is when your application has to switch from an old index to a newindex with zero downtime.

Let's say you want to reindex an index because of some reasons and you're not using aliases with your index then you need to update your application to use the new index name.

How this is helpful?

Assume that your application is using the alias instead of an index name.

Let's create an index:

PUT /my_index

Create its alias:

PUT /my_index/_alias/my_index_alias

Now you've decided to reindex your index (maybe you want to change the existing mapping).

Once documents have been reindexed correctly, you can switch your alias to point to the new index.

Note: You need to remove the alias from the old index at the same time as we add it to the new index. You can do it using _aliases endpoint atomically.

A good read : elastic

As per your question usage of maintaining two aliases for a single index:

  • Create “views” on a subset of the documents in an index.

Using multiple indices having same alias:

  • Group multiple indices under same name, which is helpful if you want to perform a single query on multiple index at the same time.

  • But you can't insert/index data using this strategy.

Upvotes: 3

Related Questions