# How Refresh works between primary and replica shards

**URL:** <https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181>\
**Category:** Elasticsearch\
**Created:** [February 13, 2020, 10:04am UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181 "2020-02-13T10:04:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konathala\_Naveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/konathala_naveen/32/54398_2.png) [@Konathala\_Naveen](https://discuss.elastic.co/u/Konathala_Naveen)\
**Post date:** [February 13, 2020, 10:04am UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181/1 "2020-02-13T10:04:57Z")

</div>

How the refresh works between primary and replica shards  
1.When the refresh happen on index.Does primary and replica shards refresh will happen in synchronous way? or After this indexing can happen asynchronously.

---

<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:** [February 13, 2020, 11:21am UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181/2 "2020-02-13T11:21:09Z")

</div>

No, refresh is not synchronized between the different copies of a shard.

---

<div class="post-metadata">

**Author:** ![Konathala\_Naveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/konathala_naveen/32/54398_2.png) [@Konathala\_Naveen](https://discuss.elastic.co/u/Konathala_Naveen)\
**Post date:** [February 13, 2020, 11:27am UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181/3 "2020-02-13T11:27:15Z")

</div>

Thanks for the quick reply. But then their is high chance that queries results will vary ,as both primary replica shards are not synchronized.

How does elasticsearch ensure,everytime,it will results the same query results ,with this approach please?

Some times in our environment,we observed difference in doc\_count from primary and replica.Is it because of that?

---

<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:** [February 13, 2020, 11:38am UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181/4 "2020-02-13T11:38:09Z")

</div>

> [@Konathala\_Naveen](#):
>
> How does elasticsearch ensure,everytime,it will results the same query results ,with this approach please?

It doesn't. If you're indexing documents then queries at different times will naturally return different results, even if your index only has one copy of each shard.

---

<div class="post-metadata">

**Author:** ![Konathala\_Naveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/konathala_naveen/32/54398_2.png) [@Konathala\_Naveen](https://discuss.elastic.co/u/Konathala_Naveen)\
**Post date:** [February 17, 2020, 1:09pm UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181/5 "2020-02-17T13:09:57Z")

</div>

No my question was. If both are happening in asynchronous fashion.  
Then there is a chance where the data which is coming from primary shard ,that data might not be available in replica shard at that particular point of time.  
So data which it displayed will be lost ,if we refresh the page,that will create lot of problems for usability know?

---

<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:** [February 17, 2020, 2:01pm UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181/6 "2020-02-17T14:01:16Z")

</div>

> [@Konathala\_Naveen](#):
>
> So data which it displayed will be lost ,if we refresh the page,that will create lot of problems for usability know?

In practice I don't think it's such a big deal. By default the different copies won't deviate by more than approximately a second's worth of traffic since that's the default refresh interval. If even this is too much then [you can use `?preference=$SESSION_ID` to direct each session to the same collection of shard copies](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-preference) across multiple requests.

---

<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:** [March 16, 2020, 2:01pm UTC](https://discuss.elastic.co/t/how-refresh-works-between-primary-and-replica-shards/219181/7 "2020-03-16T14:01:17Z")

</div>

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