Update a same document on a same time?

I have a problem when i have to update a same document with tow different thread ,
for example : there is a document like this:
{id = 1 , ware_sku=1 ,ware _ware= 2 , ……..},

but i know that the Partial Updates to Documents will have three step , retrieve - delete - reindex .
so there is a question : thread2 send update request which the source is “{ware_sku = 3} , the document will be delete ,and reindex, on the same time , the thread 1 send update request ({ware_ware= 3}) too , now thread1 maybe not retreive this document because thread2 delete it ?
is there has this problem? or I understand something wrong ?

  thank you. dears.
1 Like

The "delete" and "reindex" steps are actually atomic in Lucene, so another thread wouldn't ever see the index in between those two steps.

But there are still risks, e.g. if each thread wants to increment a count on the document.

In that case, https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html describes how multiple client side threads can safely handle conflicts when updating the same document.

The update API (https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-updates.html) will also do this retry-on-conflict for you, entirely within ES.

1 Like

At first , Thanks ! mike.

I got it, and I set retryOnConflict parameter as 10 on a updating, and it seems all right .

But there is another question , any thread wouldn't ever see the index in between those two steps?
if the thread1 is scrolling some documents and maybe do something for them (like update . delete etc.), and thread 2 is updating a document which should be fetch by thread1 , then can the thread 1 see this document in between the "delete" and "reindex" steps?

Thanks again!

thread1 will see a point-in-time view of the index (assuming you're using scan/scroll), and so it will not see any of the changes thread2 is making, and certainly not in between the delete + add of a single document that you are updating since that's atomic to Lucene.