# Is refresh in Elasticsearch atomic?

**URL:** <https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647>\
**Category:** Elasticsearch\
**Created:** [October 15, 2019, 12:30pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647 "2019-10-15T12:30:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![drd](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@drd](https://discuss.elastic.co/u/drd)\
**Post date:** [October 15, 2019, 12:30pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647/1 "2019-10-15T12:30:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [October 15, 2019, 12:40pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647/2 "2019-10-15T12:40:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![drd](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@drd](https://discuss.elastic.co/u/drd)\
**Post date:** [October 15, 2019, 1:50pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647/3 "2019-10-15T13:50:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [October 15, 2019, 1:58pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647/4 "2019-10-15T13:58:17Z")

</div>

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](https://github.com/elastic/elasticsearch/pull/26791).

---

<div class="post-metadata">

**Author:** ![drd](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@drd](https://discuss.elastic.co/u/drd)\
**Post date:** [October 15, 2019, 2:26pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647/5 "2019-10-15T14:26:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [October 15, 2019, 3:11pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647/6 "2019-10-15T15:11:43Z")

</div>

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).

---

<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 12, 2019, 3:11pm UTC](https://discuss.elastic.co/t/is-refresh-in-elasticsearch-atomic/203647/7 "2019-11-12T15:11:45Z")

</div>

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