Harold L. Brown
Harold L. Brown

Reputation: 9976

When changing the index of an Elasticsearch alias via API, do write operations immediately point to the right index after the response?

Let's say I got the alias car-alias pointing to car-index-1. I now want car-alias to point to car-index-2.

I therefore perform the following POST request to the Aliases API:

{
  "actions": [
    {
      "remove": {
        "index": "car-index-1",
        "alias": "car-alias"
      }
    },
    {
      "add": {
        "index": "car-index-2",
        "alias": "car-alias"
      }
    }
  ]
}

I receive the following response:

{
   "acknowledged": true
}

Can I now immediately index data into the car-alias and it ends up in the car-index-2?

Or does the "acknowledged": true response not guarantee that write operations point to the right index immediately?

Upvotes: 0

Views: 3433

Answers (2)

apt-get_install_skill
apt-get_install_skill

Reputation: 2908

In addition to @Val's answer:

Since in your case, the alias only points to one index, the "next" index is automatically set as the write index.

From the docs regarding the is_write_index option of the add action:

is_write_index (Optional, Boolean) If true, sets the write index or data stream for the alias.

If an alias points to multiple indices or data streams and is_write_index isn’t set, the alias rejects write requests. If an index alias points to one index and is_write_index isn’t set, the index automatically acts as the write index. [...]

Only the add action supports this parameter.

Upvotes: 1

Val
Val

Reputation: 217554

Yes, the alias is changed atomically and will point to car-index-2 immediately when the call returns.

As stated in the documentation "...during the swap, the alias has no downtime and never points to both streams at the same time."

Upvotes: 1

Related Questions