# Auto\_expand\_replicas and shard allocation filtering

**URL:** <https://discuss.elastic.co/t/auto-expand-replicas-and-shard-allocation-filtering/8928>\
**Category:** Elasticsearch\
**Created:** [September 5, 2012, 1:48am UTC](https://discuss.elastic.co/t/auto-expand-replicas-and-shard-allocation-filtering/8928 "2012-09-05T01:48:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discuss.elastic.co/u/Mauri)\
**Post date:** [September 5, 2012, 1:48am UTC](https://discuss.elastic.co/t/auto-expand-replicas-and-shard-allocation-filtering/8928/1 "2012-09-05T01:48:33Z")

</div>

Hello, If I configure the nodes in my cluster to have a node attribute  
'node.zone' with values "zone1", "zone1", etc  
and then configure an index as follows:

curl -XPUT localhost:9200/test/\_settings -d '{  
"index.routing.allocation.include.zone" : "zone1",  
"index.auto\_expand\_replicas" : "0-all"  
}'

Will elasticsearch auto expand the replica shards for index 'test' only  
within zone1 or will the auto\_expand\_replicas option ignore the shard  
allocation directives and auto replicate across the entire cluster?

Regards  
Mauri

--

---

<div class="post-metadata">

**Author:** ![Mauri](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@Mauri](https://discuss.elastic.co/u/Mauri)\
**Post date:** [September 5, 2012, 2:58pm UTC](https://discuss.elastic.co/t/auto-expand-replicas-and-shard-allocation-filtering/8928/2 "2012-09-05T14:58:11Z")

</div>

Hello, Decided to do a test to investigate this.

With an index configured with auto\_expand\_replicas="0-all" the cluster will  
try to allocate one primary and ({number nodes} - 1) replicas for each  
shard, ie a copy of each shard on each node.

However, with "index.routing.allocation.include.zone"="zone1" the cluster  
is blocked from allocating a shard (either primary or replica) to any nodes  
that are not configured with a zone attribute set to "zone1", ie  
"node.zone=zone1" in the elasticsearch.yaml config file. So if a cluster  
has 3 nodes in "zone1" and 3 nodes in "zone2" it will allocate 3 shards  
(primary + 2 x replicas) to the "zone1" nodes and mark an additional 3  
replicas as unassigned. I observed this using the elasticsearch head  
utility.

So the allocation behaviour is as desired, ie auto expand replicas to all  
nodes with a specific zone attribute.  
I do not know if the unassigned replicas will cause problems for the  
cluster.  
Can anyone add to this?

Below is the HTTP request I used to create the index

Request ---------------------------------------------  
POST /test8 HTTP/1.0  
Host: localhost:9200  
Content-Type: application/json  
Content-Length: 178

{ "settings" : { "index" : { "number\_of\_shards" : 1,  
"auto\_expand\_replicas" : "0-all", "routing" : {"allocation" :  
{"include" : {"zone" : "zone1"}}} } }}  
Response --------------------------------------------  
HTTP/1.0 200 OK  
Content-Type: application/json; charset=UTF-8  
Content-Length: 31

{"ok":true,"acknowledged":true}  
End ----------------------------------------------

Regards  
Mauri

--

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [April 7, 2013, 6:10pm UTC](https://discuss.elastic.co/t/auto-expand-replicas-and-shard-allocation-filtering/8928/3 "2013-04-07T18:10:09Z")

</div>

We are experiencing this as well. The Unassigned shards in this case (when  
auto-expand-replica is set to some value and the index has include/exclude  
stuff set) will make your cluster status be in RED state, which is bad.

I opened a ticket for this here:

> <https://github.com/elastic/elasticsearch/issues/2869>
>
> With an index configured with auto\_expand\_replicas="0-all" the cluster will try …to allocate one primary and ({number nodes} - 1) replicas for each shard, ie a copy of each shard on each node.
> 
> However, with "index.routing.allocation.include.zone"="zone1" the cluster is blocked from allocating a shard (either primary or replica) to any nodes that are not configured with a zone attribute set to "zone1", ie "node.zone=zone1" in the elasticsearch.yaml config file. So if a cluster has 3 nodes in "zone1" and 3 nodes in "zone2" it will allocate 3 shards (primary + 2 x replicas) to the "zone1" nodes and mark an additional 3 replicas as unassigned. I observed this using the elasticsearch head utility.
> 
> So the allocation behaviour is as desired, ie auto expand replicas to all nodes with a specific zone attribute, but the unassigned shards will make the cluster be in red state
> 
> See https://groups.google.com/forum/#!msg/elasticsearch/95hC-wGu7GE/BPPSWsfj8UkJ

On Wednesday, September 5, 2012 5:58:11 PM UTC+3, Mauri wrote:

> Hello, Decided to do a test to investigate this.
> 
> With an index configured with auto\_expand\_replicas="0-all" the cluster  
> will try to allocate one primary and ({number nodes} - 1) replicas for each  
> shard, ie a copy of each shard on each node.
> 
> However, with "index.routing.allocation.include.zone"="zone1" the cluster  
> is blocked from allocating a shard (either primary or replica) to any nodes  
> that are not configured with a zone attribute set to "zone1", ie  
> "node.zone=zone1" in the elasticsearch.yaml config file. So if a cluster  
> has 3 nodes in "zone1" and 3 nodes in "zone2" it will allocate 3 shards  
> (primary + 2 x replicas) to the "zone1" nodes and mark an additional 3  
> replicas as unassigned. I observed this using the elasticsearch head  
> utility.
> 
> So the allocation behaviour is as desired, ie auto expand replicas to all  
> nodes with a specific zone attribute.  
> I do not know if the unassigned replicas will cause problems for the  
> cluster.  
> Can anyone add to this?
> 
> Below is the HTTP request I used to create the index
> 
> Request ---------------------------------------------  
> POST /test8 HTTP/1.0  
> Host: localhost:9200  
> Content-Type: application/json  
> Content-Length: 178
> 
> { "settings" : { "index" : { "number\_of\_shards" : 1,  
> "auto\_expand\_replicas" : "0-all", "routing" : {"allocation" :  
> {"include" : {"zone" : "zone1"}}} } }}  
> Response --------------------------------------------  
> HTTP/1.0 200 OK  
> Content-Type: application/json; charset=UTF-8  
> Content-Length: 31
> 
> {"ok":true,"acknowledged":true}  
> End ----------------------------------------------
> 
> Regards  
> Mauri

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:42am UTC](https://discuss.elastic.co/t/auto-expand-replicas-and-shard-allocation-filtering/8928/4 "2017-07-06T02:42:21Z")

</div>


