lefloh
lefloh

Reputation: 10961

Why are Elasticsearch aliases not unique

The Elasticsearch documentation describes aliases as feature to reindex data with zero downtime:

  1. Create a new index and index the whole data
  2. Let your alias point to the new index
  3. Delete the old index

This would be a great feature if aliases would be unique but it's possible that one alias points to multiple indexes. Considering that maybe the deletion of the old index fails my application might speak to two indexes which might not be in sync. Even worse: the application doesn't know about that.

Why is it possible to reuse an alias?

Upvotes: 0

Views: 853

Answers (1)

Clarence
Clarence

Reputation: 2964

It allows you to easily have several indexes that are both used individually and together with other indexes. This is useful for example when having a logging index where sometimes you want to query the most recent (logs-recent alias) and sometimes want to query everything (logs alias). There are probably lots of other use cases but this one pops up as the first for me.

As per the documentation you can send both the remove and add in one request:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}'

After that succeeds you can remove your old index and if that fails you will just have an extra index taking up some space until its cleaned out.

Upvotes: 2

Related Questions