Is refresh in Elasticsearch atomic?

Scenario: I have my index refresh interval set to -1 (no automatic refresh). I add 20 documents to index using bulk with refresh=true. Are all documents visible at same time? The question is are Elasticsearch refreshes atomic? Are all the changes made to index since last refresh visible all at once?

No. Refreshes happen at different times on different shard copies, so you can observe intermediate states if you search before the bulk indexing operation returns.

1 Like

Thanks for the quick response. Is the refresh atomic as far as primary shards? So if I Search with a preference of primaries, to that search all documents in the above bulk put will be guaranteed to be visible?

No, if you have multiple primary shards then you will still be able to observe intermediate states. Also note that the primary preference option gives weak and misleading guarantees which is why it was removed in 7.0.

Thank you David. Any suggestions on how I could achieve consistency from the search side when doing bulk puts with a refresh (with auto refresh disabled)? There is only ever one process/thread doing bulk inserts on a given index.

Not really, no. Elasticsearch is more at the eventually-consistent end of the distributed systems spectrum and has no notion of transactions (at least, not ones that span multiple documents).

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