"Race condition" in Java

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

Yes, that is normal. Search in Elasticsearch is near real-time, 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.

To add a bit to answer above, you can use ?refresh=wait_for parameter to ensure the relationship between your operations (to guarantee that bulk will return only after the document is no longer visible)

Thanks - Enomine

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