# ES shards allocation logic

**URL:** <https://discuss.elastic.co/t/es-shards-allocation-logic/110080>\
**Category:** Elasticsearch\
**Created:** [December 4, 2017, 2:28am UTC](https://discuss.elastic.co/t/es-shards-allocation-logic/110080 "2017-12-04T02:28:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwat090](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rwat090/32/48235_2.png) [@rwat090](https://discuss.elastic.co/u/rwat090)\
**Post date:** [December 4, 2017, 2:28am UTC](https://discuss.elastic.co/t/es-shards-allocation-logic/110080/1 "2017-12-04T02:28:45Z")

</div>

Hi Everyone,

Im just trying to get my head around the logic for shards node allocation, here are some examples

Config

ES: 5.6.4  
Nodes: 2  
Nodes are split between two datacenters

Server 01 and Server 02 node.master role is enabled (default settings).

curl -XGET ‘server01:9200/\_cat/nodes?v&h=id,ip,port,v,m'  
id ip port v m  
B2uB server01 9300 5.6.4 \*  
2Dme server02 9300 5.6.4 -

Examples

1. Create an Index “1 Shared and 0 Replication”

Process  
— On server 1  
— Create Index “1 Shared and 0 Replication”

- Complete Bulk index
- After full index complete enable replication

Problem

- Each time we create new index to Server1 the shard has 50% chance that the Primary shard will be created on Server2  
(Even I use server1 to create the index)
- The problem is the VM’s are located in two different datacenter’s — I need each Shard’s to be created on Server1

1. Create an Index “1 Shared and 1 Replication”

Process

- Create Index

- Disable replication

- Complete Bulk index

- After full index complete enable replication

- The Primary Shard is always created on server 02 or 01

if increase the number of Shards they are split between server1 / server2. (No replication)

- So shards 0 2 4 are created on server2
- And shards 1 3 create on server1

I would like all my Primary Shards to be created on Server1

\*\*\* I have been looking at “/\_cluster/settings” and “cluster.routing.allocation.enable” \*\*\*\*\*\*

new\_primaries - Allows shard allocation only for primary shards for new indices.  
all - (default) Allows shard allocation for all kinds of shards.

Server1

{  
"persistent" : { },  
"transient" : {  
"cluster" : {  
"routing" : {  
"allocation" : {  
"enable" : "all"  
}  
}  
},

Server 2

{  
"persistent" : { },  
"transient" : {  
"cluster" : {  
"routing" : {  
"allocation" : {  
"enable" : "all"  
}  
}  
},

Am I going down the wrong path or do you have any tips or tricks around shard creation ?

I noticed the following POST for 0.20

> [@What's the logic or algorithm for allocation of primary shard or replica when node joins cluster?](https://discuss.elastic.co/t/whats-the-logic-or-algorithm-for-allocation-of-primary-shard-or-replica-when-node-joins-cluster/9442):
>
> Hi all, I have googled a lot but found nothing about the logic for allocation of shard and replica when node joins the cluster. If it's not evenly distributed shards and replicas, can I controll allocation of shards and replicas? What I mean manually controll the allocation of shards and replicas in order to making a balance. any pointer is a great help, thanks. SuoNayi --

Cheers

Reid

---

<div class="post-metadata">

**Author:** ![rwat090](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rwat090/32/48235_2.png) [@rwat090](https://discuss.elastic.co/u/rwat090)\
**Post date:** [December 4, 2017, 3:37am UTC](https://discuss.elastic.co/t/es-shards-allocation-logic/110080/2 "2017-12-04T03:37:00Z")

</div>

Is there an easier way to set shard location when creating an index instead of using Move process after the index / shards have been allocated

PUT /\_cluster/  
settings  
{  
"transient" : {  
"cluster.routing.allocation.enable" : "none"  
}  
}

PUT \_cluster/reroute  
{  
"commands" : [  
{  
"move" : {  
"index" : "test", "shard" : 0,  
"from\_node" : "server02", "to\_node" : "server01"  
}  
}  
]  
}  
‘

PUT /\_cluster/  
settings  
{  
"transient" : {  
"cluster.routing.allocation.enable" : “all"  
}  
}

Cheers

Reid

---

<div class="post-metadata">

**Author:** ![rwat090](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rwat090/32/48235_2.png) [@rwat090](https://discuss.elastic.co/u/rwat090)\
**Post date:** [December 5, 2017, 1:24am UTC](https://discuss.elastic.co/t/es-shards-allocation-logic/110080/3 "2017-12-05T01:24:15Z")

</div>

I will add the allocation setting on Index Creation

"settings": {  
"index": {  
"number\_of\_shards": "1",  
"number\_of\_replicas": 0,  
"routing.allocation.include.\_name": "node"  
},

---

<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:** [January 2, 2018, 1:24am UTC](https://discuss.elastic.co/t/es-shards-allocation-logic/110080/4 "2018-01-02T01:24:16Z")

</div>

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