Coder
Coder

Reputation: 519

Is it possible to update indices in Elasticsearch with zero downtime?

I am trying to achieve updating the data in the indices of Elasticsearch with zero downtime but I am not sure how to achieve this. Can anyone assist me how I can do so?

For example: If I have an index of name my_es_index and I want to update the data in that particular index with zero downtime so that the old data is still there on one of the node while someone is performing certain query but parallelly in the backend , we are updating the data on that index.

Is it possible to achieve? If yes, please help me with how I can proceed.

Upvotes: 0

Views: 1005

Answers (2)

dravit
dravit

Reputation: 607

Unless you are to update the mapping of an existing field and preserving the name of the fields is required, I don't think taking the cluster down is needed.

While the above article is a good read and might be treated as best practices, ES is a lot flexible. Unlike MySQL/SQL, it allows you to update existing documents.

Adding a new field

Let's call the new field to be added as x.

  • add mapping to the index for x.
  • make the code changes such that going forward, all the new documents have this new field x.
  • while all the new documents have the field x, write-up a script which updates the older documents and adds this field x.
  • once you are sure that all the documents have the field x, you may enable the feature you added this field for.

Updating mapping of a field

Let's again call the field to be updated as x (assuming the name of the field is not the prime concern).

  • create a new field, say new_x (add correct mapping to the index).
  • follow the above steps to ensure new_x has the data (slight change that we need to ensure both x and new_x have this data).
  • once all the documents in the index have the field new_x, simply refactor the code to use new_x instead of x.

While one might argue that above two approaches are in a way hacks, it saves you time, effort and cost to boot up a new ES instance and manage the aliases.

Upvotes: 0

Vy Do
Vy Do

Reputation: 52536

You build/create another index (we called new index), then switch from old index to new index, then delete old index.

Read more at https://medium.com/craftsmenltd/rebuild-elasticsearch-index-without-downtime-168363829ea4

Upvotes: 3

Related Questions