# "Race condition" in Java

**URL:** <https://discuss.elastic.co/t/race-condition-in-java/317615>\
**Category:** Elasticsearch\
**Created:** [October 27, 2022, 12:49pm UTC](https://discuss.elastic.co/t/race-condition-in-java/317615 "2022-10-27T12:49:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Gattinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_gattinger/32/99690_2.png) [@Michael\_Gattinger](https://discuss.elastic.co/u/Michael_Gattinger)\
**Post date:** [October 27, 2022, 12:49pm UTC](https://discuss.elastic.co/t/race-condition-in-java/317615/1 "2022-10-27T12:49:02Z")

</div>

Hi,  
what i am experiencing right now is that a document that should be already deleted will be still listet if a search is done directly after the deletion.

a) indexing the document xyz  
b) doing other Elastic-related stuff  
c) building a bulk request with approx 15 tasks (has deletion of document xyz) and executing it  
d) print bulkresponce  
e) outprint says that document xyz is deleted  
f) search match all on index  
g) printing search, document xyz is still listet.

If i add a thread.sleep(1000) between e and f then document xyz will be not found by matchall.

Is that normal?

Thanks - Enomine

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 27, 2022, 1:02pm UTC](https://discuss.elastic.co/t/race-condition-in-java/317615/2 "2022-10-27T13:02:59Z")

</div>

Yes, that is normal. Search in Elasticsearch is [near real-time](https://www.elastic.co/guide/en/elasticsearch/reference/8.4/near-real-time.html), which means changes will only show up in search results (or be removed from it in your case) after a refresh has occurred, and this is a periodic task as it is expensive.

---

<div class="post-metadata">

**Author:** ![etki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/etki/32/112603_2.png) [@etki](https://discuss.elastic.co/u/etki)\
**Post date:** [October 27, 2022, 3:00pm UTC](https://discuss.elastic.co/t/race-condition-in-java/317615/3 "2022-10-27T15:00:20Z")

</div>

To add a bit to answer above, you can use [?refresh=wait\_for](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html) parameter to ensure the relationship between your operations (to guarantee that bulk will return only after the document is no longer visible)

---

<div class="post-metadata">

**Author:** ![Michael\_Gattinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_gattinger/32/99690_2.png) [@Michael\_Gattinger](https://discuss.elastic.co/u/Michael_Gattinger)\
**Post date:** [October 28, 2022, 4:09am UTC](https://discuss.elastic.co/t/race-condition-in-java/317615/4 "2022-10-28T04:09:15Z")

</div>

Thanks - Enomine

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 25, 2022, 4:09am UTC](https://discuss.elastic.co/t/race-condition-in-java/317615/5 "2022-11-25T04:09:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
