# Primary shard rebalancing

**URL:** <https://discuss.elastic.co/t/primary-shard-rebalancing/6173>\
**Category:** Elasticsearch\
**Created:** [December 15, 2011, 10:34pm UTC](https://discuss.elastic.co/t/primary-shard-rebalancing/6173 "2011-12-15T22:34:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kellan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kellan/32/3029_2.png) [@Kellan](https://discuss.elastic.co/u/Kellan)\
**Post date:** [December 15, 2011, 10:34pm UTC](https://discuss.elastic.co/t/primary-shard-rebalancing/6173/1 "2011-12-15T22:34:28Z")

</div>

I have a 2-node (1 process on each node) ES cluster setup with 2  
shards and 1 replica per shard. With this configuration, I would think  
that the ideal balance would be 1 primary shard and 1 replica shard on  
each node, and indeed after the initial data insert, this is the case.  
However, after one or both processes are restarted, the cluster seems  
to "rebalance" itself with both primary shards on one node and both  
replicas on the other. Is there a way to direct the cluster back  
toward the 1 primary/1 replica per node configuration? Is it correct  
that all updates go to the primary shard? My index configuration is  
below.

Thanks for any help you can provide,  
Kellan

index:  
number\_of\_shards: 2  
number\_of\_replicas: 1

bootstrap.mlockall: true

cluster.name: shardtest

network.host: ip1

http.port: 9200

transport.port: 9400

discovery.zen.ping.multicast.enabled: false  
discovery.zen.ping.unicast.hosts: [ip1, ip2]  
discovery.zen.minimum\_master\_nodes: 2

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 16, 2011, 3:48pm UTC](https://discuss.elastic.co/t/primary-shard-rebalancing/6173/2 "2011-12-16T15:48:10Z")

</div>

There is no meaning to have balanced primary allocation since primary and  
replica shards do the same work.

On Fri, Dec 16, 2011 at 12:34 AM, Kellan [wampleek@gmail.com](mailto:wampleek@gmail.com) wrote:

> I have a 2-node (1 process on each node) ES cluster setup with 2  
> shards and 1 replica per shard. With this configuration, I would think  
> that the ideal balance would be 1 primary shard and 1 replica shard on  
> each node, and indeed after the initial data insert, this is the case.  
> However, after one or both processes are restarted, the cluster seems  
> to "rebalance" itself with both primary shards on one node and both  
> replicas on the other. Is there a way to direct the cluster back  
> toward the 1 primary/1 replica per node configuration? Is it correct  
> that all updates go to the primary shard? My index configuration is  
> below.
> 
> Thanks for any help you can provide,  
> Kellan
> 
> index:  
> number\_of\_shards: 2  
> number\_of\_replicas: 1
> 
> bootstrap.mlockall: true
> 
> cluster.name: shardtest
> 
> network.host: ip1
> 
> http.port: 9200
> 
> transport.port: 9400
> 
> discovery.zen.ping.multicast.enabled: false  
> discovery.zen.ping.unicast.hosts: [ip1, ip2]  
> discovery.zen.minimum\_master\_nodes: 2

---

<div class="post-metadata">

**Author:** ![Kellan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kellan/32/3029_2.png) [@Kellan](https://discuss.elastic.co/u/Kellan)\
**Post date:** [December 16, 2011, 7:44pm UTC](https://discuss.elastic.co/t/primary-shard-rebalancing/6173/3 "2011-12-16T19:44:40Z")

</div>

Can replica shards handle data inserts? I thought the primary shard  
handled all data inserts and reindexing.

On Dec 16, 10:48 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> There is no meaning to have balanced primary allocation since primary and  
> replica shards do the same work.
> 
> On Fri, Dec 16, 2011 at 12:34 AM, Kellan [wampl...@gmail.com](mailto:wampl...@gmail.com) wrote:
> 
> > I have a 2-node (1 process on each node) ES cluster setup with 2  
> > shards and 1 replica per shard. With this configuration, I would think  
> > that the ideal balance would be 1 primary shard and 1 replica shard on  
> > each node, and indeed after the initial data insert, this is the case.  
> > However, after one or both processes are restarted, the cluster seems  
> > to "rebalance" itself with both primary shards on one node and both  
> > replicas on the other. Is there a way to direct the cluster back  
> > toward the 1 primary/1 replica per node configuration? Is it correct  
> > that all updates go to the primary shard? My index configuration is  
> > below.
> 
> > Thanks for any help you can provide,  
> > Kellan
> 
> > index:  
> > number\_of\_shards: 2  
> > number\_of\_replicas: 1
> 
> > bootstrap.mlockall: true
> 
> > cluster.name: shardtest
> 
> > network.host: ip1
> 
> > http.port: 9200
> 
> > transport.port: 9400
> 
> > discovery.zen.ping.multicast.enabled: false  
> > discovery.zen.ping.unicast.hosts: [ip1, ip2]  
> > discovery.zen.minimum\_master\_nodes: 2

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 16, 2011, 8:58pm UTC](https://discuss.elastic.co/t/primary-shard-rebalancing/6173/4 "2011-12-16T20:58:49Z")

</div>

Yes, replicas also handle indexing in order to provide (near) realtime  
support search and HA.

On Fri, Dec 16, 2011 at 9:44 PM, Kellan [wampleek@gmail.com](mailto:wampleek@gmail.com) wrote:

> Can replica shards handle data inserts? I thought the primary shard  
> handled all data inserts and reindexing.
> 
> On Dec 16, 10:48 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > There is no meaning to have balanced primary allocation since primary and  
> > replica shards do the same work.
> > 
> > On Fri, Dec 16, 2011 at 12:34 AM, Kellan [wampl...@gmail.com](mailto:wampl...@gmail.com) wrote:
> > 
> > > I have a 2-node (1 process on each node) ES cluster setup with 2  
> > > shards and 1 replica per shard. With this configuration, I would think  
> > > that the ideal balance would be 1 primary shard and 1 replica shard on  
> > > each node, and indeed after the initial data insert, this is the case.  
> > > However, after one or both processes are restarted, the cluster seems  
> > > to "rebalance" itself with both primary shards on one node and both  
> > > replicas on the other. Is there a way to direct the cluster back  
> > > toward the 1 primary/1 replica per node configuration? Is it correct  
> > > that all updates go to the primary shard? My index configuration is  
> > > below.
> > 
> > > Thanks for any help you can provide,  
> > > Kellan
> > 
> > > index:  
> > > number\_of\_shards: 2  
> > > number\_of\_replicas: 1
> > 
> > > bootstrap.mlockall: true
> > 
> > > cluster.name: shardtest
> > 
> > > network.host: ip1
> > 
> > > http.port: 9200
> > 
> > > transport.port: 9400
> > 
> > > discovery.zen.ping.multicast.enabled: false  
> > > discovery.zen.ping.unicast.hosts: [ip1, ip2]  
> > > discovery.zen.minimum\_master\_nodes: 2

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [December 16, 2011, 9:40pm UTC](https://discuss.elastic.co/t/primary-shard-rebalancing/6173/5 "2011-12-16T21:40:41Z")

</div>

Kellan,

the data is first indexed on primary shard and the primary shard then makes  
sure it is also replicated to all replicas. So if you have two nodes, two  
indices each with 1 shard and 1 replica then even if each primary would be  
located on different node the indexing would still propagate every document  
to both nodes equally.

Regards,  
Lukas

On Fri, Dec 16, 2011 at 9:58 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Yes, replicas also handle indexing in order to provide (near) realtime  
> support search and HA.
> 
> On Fri, Dec 16, 2011 at 9:44 PM, Kellan [wampleek@gmail.com](mailto:wampleek@gmail.com) wrote:
> 
> > Can replica shards handle data inserts? I thought the primary shard  
> > handled all data inserts and reindexing.
> > 
> > On Dec 16, 10:48 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > There is no meaning to have balanced primary allocation since primary  
> > > and  
> > > replica shards do the same work.
> > > 
> > > On Fri, Dec 16, 2011 at 12:34 AM, Kellan [wampl...@gmail.com](mailto:wampl...@gmail.com) wrote:
> > > 
> > > > I have a 2-node (1 process on each node) ES cluster setup with 2  
> > > > shards and 1 replica per shard. With this configuration, I would think  
> > > > that the ideal balance would be 1 primary shard and 1 replica shard on  
> > > > each node, and indeed after the initial data insert, this is the case.  
> > > > However, after one or both processes are restarted, the cluster seems  
> > > > to "rebalance" itself with both primary shards on one node and both  
> > > > replicas on the other. Is there a way to direct the cluster back  
> > > > toward the 1 primary/1 replica per node configuration? Is it correct  
> > > > that all updates go to the primary shard? My index configuration is  
> > > > below.
> > > 
> > > > Thanks for any help you can provide,  
> > > > Kellan
> > > 
> > > > index:  
> > > > number\_of\_shards: 2  
> > > > number\_of\_replicas: 1
> > > 
> > > > bootstrap.mlockall: true
> > > 
> > > > cluster.name: shardtest
> > > 
> > > > network.host: ip1
> > > 
> > > > http.port: 9200
> > > 
> > > > transport.port: 9400
> > > 
> > > > discovery.zen.ping.multicast.enabled: false  
> > > > discovery.zen.ping.unicast.hosts: [ip1, ip2]  
> > > > discovery.zen.minimum\_master\_nodes: 2

---

<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 6, 2017, 3:45am UTC](https://discuss.elastic.co/t/primary-shard-rebalancing/6173/6 "2017-07-06T03:45:05Z")

</div>


