Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the order of operations guaranteed in a bulk update?

I am sending delete and index requests to elasticsearch in bulk (the example is adapted from the docs):

{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }

The sequence above is intended to first delete a possible document with _id=1, then index a new document with the same _id=1.

Is the order of the actions guaranteed? In other words, for the example above, can I be sure that the delete will not touch the document indexed afterwards (because the order would not be respected for a reason or another)?

like image 459
WoJ Avatar asked Sep 04 '25 17:09

WoJ


2 Answers

The delete operation is useless in this scenario, if you simply index a document with the same ID, it will automatically and implicitly delete/replace the previous document with the same ID.

So if document with ID=1 already exists, simply sending the below command will replace it (read delete and re-index it)

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
like image 65
Val Avatar answered Sep 07 '25 05:09

Val


According to an Elastic Team Member:

Elasticsearch is distributed and concurrent. We do not guarantee that requests are executed in the order they are received.

https://discuss.elastic.co/t/are-bulk-index-operations-serialized/83770/6

like image 21
wdickerson Avatar answered Sep 07 '25 05:09

wdickerson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!