# Does the replica shards automatically get deleted after reallocation using the cluster reroute api when nodes go down

**URL:** https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265
**Category:** Elasticsearch
**Created:** [January 14, 2016, 7:52pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265 "2016-01-14T19:52:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Jaswinder\_Singh](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@Jaswinder\_Singh](https://discuss.elastic.co/u/Jaswinder_Singh)
#### Post date: [January 14, 2016, 7:52pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/1 "2016-01-14T19:52:21Z")

</div>

Hello,  
We are manually reallocating shards to active nodes using the Cluster Reroute API after one or more nodes go down and indices turn red. We basically find the unassigned shards for indices that are red and move the primary shards to a currently active node and ES automatically creates the replica shards. We want to ensure that we dont have any stale data lying around. The elasticsearch documentation on cluster reroute API states the following:

The allow\_primary parameter will force a new empty primary shard to be allocated without any data. If a node which has a copy of the original primary shard (including data) rejoins the cluster later on, that data will be deleted: the old shard copy will be replaced by the new live shard copy.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html)

Our question is:  
If a node which has a copy of the original replica shard(including data) rejoins the cluster later on, Does that data gets deleted as well?  
In other words,  
Does ES clean up data for both primary and replica shards if they have been reallocated and later, the original node containing those shards comes back into the cluster?

---

<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: [January 14, 2016, 11:34pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/2 "2016-01-14T23:34:14Z")

</div>

Why are you having to do this manually? ES should just manage this transparently.

> [@Jaswinder\_Singh](#):
>
> If a node which has a copy of the original replica shard(including data) rejoins the cluster later on, Does that data gets deleted as well?

Depends what version you are on.

---

<div class="post-metadata">

### Author: ![Jaswinder\_Singh](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@Jaswinder\_Singh](https://discuss.elastic.co/u/Jaswinder_Singh)
#### Post date: [January 14, 2016, 11:56pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/3 "2016-01-14T23:56:04Z")

</div>

ES seems to rebalance when one or more shards are available. For instance, if index is configured to have 2 copies of shards(one primary and one replica). If both primary and replica shards are lost due to two different nodes going down before the ES has a chance to rebalance. Then, the index will go red and never recover. We found that during our testing. We are manually reallocating the primary shard onto an active node and then ES automatically creates a replica shard. These have no data.

We are on 1.7.3

---

<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: [January 14, 2016, 11:59pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/4 "2016-01-14T23:59:05Z")

</div>

Then that's expected, ES cannot recover data from a shard that no longer exists in the cluster anywhere.

---

<div class="post-metadata">

### Author: ![Jaswinder\_Singh](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@Jaswinder\_Singh](https://discuss.elastic.co/u/Jaswinder_Singh)
#### Post date: [January 19, 2016, 7:07pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/5 "2016-01-19T19:07:04Z")

</div>

What is the behavior if:

1. both primary and replica shards are lost due to two nodes(1 and 2) going down.
2. Both are re-assigned to active nodes using the reallocate API.
3. Nodes(1 and 2) that were down re-join the cluster.

The ES documentation says that the PRIMARY shard on node rejoining the cluster will be deleted. But, does not mention anything about the replica shard.  
Does the replica shard gets deleted as well?

---

<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: [January 19, 2016, 8:53pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/6 "2016-01-19T20:53:20Z")

</div>

Yep it will becuase there will be an existing replica.

Where is that in the docs, we can get it updated.

---

<div class="post-metadata">

### Author: ![Jaswinder\_Singh](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@Jaswinder\_Singh](https://discuss.elastic.co/u/Jaswinder_Singh)
#### Post date: [January 19, 2016, 9:00pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/7 "2016-01-19T21:00:28Z")

</div>

It is in the Warning section on the following page:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html)

Thanks a ton Mark 🙂

---

<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: [January 20, 2016, 7:37am UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/8 "2016-01-20T07:37:07Z")

</div>

FYI [https://github.com/elastic/elasticsearch/issues/16113](https://github.com/elastic/elasticsearch/issues/16113)

---

<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: [July 5, 2017, 11:23pm UTC](https://discuss.elastic.co/t/does-the-replica-shards-automatically-get-deleted-after-reallocation-using-the-cluster-reroute-api-when-nodes-go-down/39265/9 "2017-07-05T23:23:08Z")

</div>


