# Elasticsearch primary and replica shards not sync after bulk load

**URL:** <https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302>\
**Category:** Elasticsearch\
**Created:** [July 17, 2018, 9:51am UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302 "2018-07-17T09:51:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yanwang](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@yanwang](https://discuss.elastic.co/u/yanwang)\
**Post date:** [July 17, 2018, 9:51am UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/1 "2018-07-17T09:51:48Z")

</div>

Hi Guys,

My team has been using the elasticsearch on aws ec2 for searching for about 2 years. We are always bothered by the out-of-sync issue between primary and replica shards. In our elasticsearch cluster we have mainly 2 indices, each of which has 6 primary shards, and 2 replicas for each shards(namely 6 primary shards, 12 replica shards, totally 18 for every index). One index is used for searching, so it just has partial data but more fielddata in the mapping. Another one holds the full data but it is just used to query by id. We do bulk load regularly every monday to both of these 2 indices with the same dataset by our elasticsearch-consumer.

But the current issue is, after the bulk load with the latest data, we also do a bulk delete to those data which is not updated before the timestamp of beginning of bulk load. We keep this running a period of time, and then query by search-index/search-type/\_search?sort=publishDate, will see a few docs published 1 or 2 month ago are still live in the index. I hit the stats API \_stats?level=shards, and the results show the primary and replica shards have different count of docs.

Also, if I make the timestamp query, for different tries, the elasticsearch returns different results. Sometimes the total of results is 0, but sometimes it has 6 or 8 or more. But if I set the preference to \_primary, the results is just 0, which is desirable. Correspondingly, if I change preference to \_replica, I will see the results are more than 0.

All the foundings above show the fact that in our consumer, after the bulk load and bulk deletion(there are 15 mins interval between these 2 operations), the elasticsearch does not successfully sync up the different shards. I tried to run \_flush/synced but it also fails because we keep indexing data in the meanwhile. It is not possible for us to pause and do the flush.

Does anyone have any thoughts about solving this issue? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 17, 2018, 9:53am UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/2 "2018-07-17T09:53:06Z")

</div>

What version are you on.

---

<div class="post-metadata">

**Author:** ![yanwang](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@yanwang](https://discuss.elastic.co/u/yanwang)\
**Post date:** [July 17, 2018, 10:12am UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/3 "2018-07-17T10:12:57Z")

</div>

The current version is 5.1.1 but we are planning to upgrade to 6.2.3

---

<div class="post-metadata">

**Author:** ![yanwang](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@yanwang](https://discuss.elastic.co/u/yanwang)\
**Post date:** [July 19, 2018, 8:52pm UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/4 "2018-07-19T20:52:09Z")

</div>

anyone has any thoughts? Could it be a bug?

---

<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:** [July 19, 2018, 8:55pm UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/5 "2018-07-19T20:55:02Z")

</div>

Are you changing the refresh interval during bulk load? If so, do you run a manual refresh once the bulk upload has completed?

---

<div class="post-metadata">

**Author:** ![yanwang](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@yanwang](https://discuss.elastic.co/u/yanwang)\
**Post date:** [July 19, 2018, 9:12pm UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/6 "2018-07-19T21:12:21Z")

</div>

We did not change the refresh interval in the bulk load. Yes we manually refresh the table and then run flush/sync but it failed because of some pending operations. The thing is I can even see the document which was published a few weeks ago. Not sure the reason why es failed to delete the in the deleting process followed by the bulk load.

---

<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:** [July 19, 2018, 9:17pm UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/7 "2018-07-19T21:17:04Z")

</div>

Do you have any cluster or index settings that are not standard? How many nodes do you have in the cluster? What does your `elasticsearch.yml` file look like?

---

<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:** [August 16, 2018, 9:17pm UTC](https://discuss.elastic.co/t/elasticsearch-primary-and-replica-shards-not-sync-after-bulk-load/140302/8 "2018-08-16T21:17:17Z")

</div>

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