# What's the expected behaviour when a document is updated and deleted in the same bulk request?

**URL:** <https://discuss.elastic.co/t/whats-the-expected-behaviour-when-a-document-is-updated-and-deleted-in-the-same-bulk-request/383566>\
**Category:** Elasticsearch\
**Created:** [November 20, 2025, 5:12pm UTC](https://discuss.elastic.co/t/whats-the-expected-behaviour-when-a-document-is-updated-and-deleted-in-the-same-bulk-request/383566 "2025-11-20T17:12:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![js\_herbert](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@js\_herbert](https://discuss.elastic.co/u/js_herbert)\
**Post date:** [November 20, 2025, 5:12pm UTC](https://discuss.elastic.co/t/whats-the-expected-behaviour-when-a-document-is-updated-and-deleted-in-the-same-bulk-request/383566/1 "2025-11-20T17:12:25Z")

</div>

Hi all,

A quick question about bulk requests. We have some code that we suspect is occasionally including an index and a delete operation for the same document in the same bulk request. The order of the operations dictates what we expect to happen — deletes after indexes should result in a deletion, and indexes after deletes should result in the object being indexed.

I’m wondering how ES is supposed to behave when that happens: I can’t find documentation to give a specification. Experimenting locally with a script and clusters of 1-3 nodes, I can see that the ordering does seems to matter: a bulk update that contains [delete doc n, update doc n] leaves the doc in the index, whereas [update doc n, delete doc n] removes it. I can run that in a tight loop and it seems deterministic.

But, is it? There’s nothing in the documentation for [bulk updates](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk) that I can see that defines this behaviour (we’re running an older version of Elasticsearch, 7.8, but the docs for them IIRC are similarly unclear). And, at a glance (I am absolutely not familiar with the ES codebase, but very willing to spelunk!), there’s nothing in the [bulk request handler code](https://github.com/elastic/elasticsearch/blob/38fa6d655c3514a500adbc528e06671f4d165137/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java#L231) that suggests any validation is done on the request, which might leave the order of operations up to the network or some other race condition.

Does anyone know where I might find a categorical answer to this question?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Tortoise](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tortoise/32/147587_2.png) [@Tortoise](https://discuss.elastic.co/u/Tortoise)\
**Post date:** [November 21, 2025, 1:49pm UTC](https://discuss.elastic.co/t/whats-the-expected-behaviour-when-a-document-is-updated-and-deleted-in-the-same-bulk-request/383566/2 "2025-11-21T13:49:19Z")

</div>

Hello @js_herbert

Welcome to the community!!

I believe below post might answer your query :

> <https://stackoverflow.com/questions/66527009/elasticsearch-multiple-index-request-on-same-document-id-in-bulk-api>

Thanks!!

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [November 21, 2025, 5:29pm UTC](https://discuss.elastic.co/t/whats-the-expected-behaviour-when-a-document-is-updated-and-deleted-in-the-same-bulk-request/383566/3 "2025-11-21T17:29:26Z")

</div>

Hi @js_herbert

I think these are 2 good references as well

> [@Elastic search bulk request API - Is the 'order' of document writing guaranteed](https://discuss.elastic.co/t/elastic-search-bulk-request-api-is-the-order-of-document-writing-guaranteed/208055/6):
>
> Thanks for the clarification.

And from the main Lucene Committer himself

> [@Order of \_bulk request operations](https://discuss.elastic.co/t/order-of--bulk-request-operations/98124/2):
>
> You can rely on the fact that operations on the same document (same \_index, \_type and \_id) will be in order. However you can't assume anything for documents that have different indices/types/ids.

A subtlely is that even for the gaurunteed order on the same (same \_index, \_type and \_id) if one early operation fails you still may not get the expected result.
