# Primary Shards Unassigned but still Cluster State health Yellow

**URL:** <https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189>\
**Category:** Elasticsearch\
**Created:** [April 10, 2019, 9:47am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189 "2019-04-10T09:47:30Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 9:47am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/1 "2019-04-10T09:47:31Z")

</div>

I was testing by Creating two dedicated master node and one data node. So I put down my data node from the Cluster and then tried to create new Index by `curl -X PUT "localhost:9200/customer?pretty"`  
where customer is the name of my index. The response of this was  
{  
"acknowledged" : true,  
"shards\_acknowledged" : false,  
"index" : "customer"  
}

So the shards are unassigned. Even the primary shards are unassigned. And when I do \_cat/indices

```
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer 4te5lNcERcOwNiQjcRxBUA 5 1             

```

The health of the Index is **Yellow** and the Cluster state is even yellow.  
Why is that unexpected behavior since primary shards are even unassigned . (\_cat/shards response)  
customer 3 p UNASSIGNED  
customer 3 r UNASSIGNED  
customer 4 p UNASSIGNED  
customer 4 r UNASSIGNED  
customer 2 p UNASSIGNED  
customer 2 r UNASSIGNED  
customer 1 p UNASSIGNED  
customer 1 r UNASSIGNED  
customer 0 p UNASSIGNED  
customer 0 r UNASSIGNED

Why is this unusual behavior since primary are unassigned but still Cluster State is Yellow?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 10:11am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/2 "2019-04-10T10:11:19Z")

</div>

A newly-created index doesn't immediately cause the cluster health to be red:

> <https://github.com/elastic/elasticsearch/blob/d5e8a5cd6910ac75042cffc64012b506933490f1/server/src/main/java/org/elasticsearch/cluster/health/ClusterShardHealth.java#L185-L211>

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 10:36am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/3 "2019-04-10T10:36:49Z")

</div>

The documentation mentions that if the Index is still in **INITIALIZING** state then the Cluster State is Yellow. But in my scenario the Index State is **UNASSIGNED**.

> <https://github.com/elastic/elasticsearch/blob/d5e8a5cd6910ac75042cffc64012b506933490f1/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java>

> /\*\*  
> \* The shard is unassigned (not allocated to any node).  
> \*/  
> public boolean unassigned() {  
> return state == ShardRoutingState.UNASSIGNED;  
> }

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 10:38am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/4 "2019-04-10T10:38:52Z")

</div>

This is true, but doesn't seem to be relevant. If a primary is `UNASSIGNED` then the logic I shared applies, allowing the health to report as yellow under some circumstances.

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 10:43am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/5 "2019-04-10T10:43:43Z")

</div>

So after what time the Cluster state will be RED? Supposing that data node never recovers.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 10:46am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/6 "2019-04-10T10:46:18Z")

</div>

The cluster will go red if the shards can definitely not be allocated anywhere:

> [@DavidTurner](#):
>
> `unassignedInfo.getLastAllocationStatus() != AllocationStatus.DECIDERS_NO`

It will also go red if they are allocated and then this allocation fails:

> [@DavidTurner](#):
>
> `unassignedInfo.getNumFailedAllocations() == 0`

If the shard is not successfully allocated then eventually one of these cases will happen.

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 11:11am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/7 "2019-04-10T11:11:14Z")

</div>

> [@DavidTurner](#):
>
> It will also go red if they are allocated and then this allocation fails:

So the Elasticsearch will internally try to make attempts to allocate as per setting. (which is 5 by default) `index.allocation.max_retries` . Then it will turn RED. Or one needs to do a reroute and if that reroute fails then it will turn RED?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 11:33am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/8 "2019-04-10T11:33:35Z")

</div>

No, the health will turn RED if any attempt fails, even if it will still retry:

```auto
unassignedInfo.getNumFailedAllocations() == 0

```

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 11:38am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/9 "2019-04-10T11:38:02Z")

</div>

I waited for a long time to turn RED. But it never turn RED. So is it not trying allocation again until it reaches `index.allocation.max_retries` . But as I know ElasticSearch internally tries to allocate primary shards till this count. Suppose it had tried and each try it didnt find the data node, eventually it should be turning RED. But is not. I havent changed any settings in the elasticsearch.yml file except the setting for dedicated Master Node. Can u pls tell why is this behaviour?  
(Just a beginner in ElasticSearch. Pls keep patience.)

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 11:40am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/10 "2019-04-10T11:40:54Z")

</div>

I see, this wasn't clear from your initial post. It sounds like you're interested in why these shards are not allocated, not why the health is yellow instead of red. The best way to answer that is with the [allocation explain API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-allocation-explain.html):

```auto
GET /_cluster/allocation/explain
{
  "index": "customer",
  "shard": 0,
  "primary": true
}

```

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 11:47am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/11 "2019-04-10T11:47:46Z")

</div>

I used this allocations explain API and as expected it told the same reason .( as it is not having any data node.) I am actually more interested in turning it RED deliberately . I want to know when will this turn into RED as it is currently yellow. And if it internally tries to make attempts for allocation until `index.allocation.max_retries` count. And if this count eventually will exceed so why is this not turning RED? as it finally fails to allocate this shard on data node(and i dont have any data node)

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 11:55am UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/12 "2019-04-10T11:55:59Z")

</div>

Please could you share the full output of the allocation explain API? This sounds unexpected, but it's hard to be sure without seeing all the details.

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 12:04pm UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/13 "2019-04-10T12:04:13Z")

</div>

> {  
> "index" : "customer",  
> "shard" : 0,  
> "primary" : true,  
> "current\_state" : "unassigned",  
> "unassigned\_info" : {  
> "reason" : "INDEX\_CREATED",  
> "at" : "2019-04-10T10:29:55.937Z",  
> "last\_allocation\_status" : "no\_attempt"  
> },  
> "can\_allocate" : "no",  
> "allocate\_explanation" : "cannot allocate because allocation is not permitted to any of the nodes"  
> }

As I am not having any data node so it is unable to allocate in any node. This is understood. But since Elasticsearch internally tries to allocate till `index.allocation.max_retries` count. And eventually this count will exceed . and after it exceeds the status should turn RED. but is not. It is still yellow. Can u pls where is the issue? As I want to see the state as RED

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 12:28pm UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/14 "2019-04-10T12:28:15Z")

</div>

Ok, I see. We don't even bother trying to assign any shards if there aren't any data nodes in the cluster, so the assignment never fails and hence the health never goes RED:

> <https://github.com/elastic/elasticsearch/blob/abd861bb9191a3e3edd4f92f7d5c586dfa90281d/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java#L117-L120>

I suppose you could consider this a bug, but it's only possible to trigger this in very strange circumstances. Note that a cluster with no data nodes would already have `RED` health if you'd created any indices before shutting the last data node down. I opened a bug report here:

> <https://github.com/elastic/elasticsearch/issues/41073>

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 12:33pm UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/15 "2019-04-10T12:33:44Z")

</div>

> [@DavidTurner](#):
>
> Note that a cluster with no data nodes would already have `RED` health if you'd created any indices before shutting the last data node down.

Yes, you are correct here. And I know about it too.

> [@DavidTurner](#):
>
> I suppose you could consider this a bug, but it's only possible to trigger this in very strange circumstances.

And I knew It from the beginning there is some kind of a bug.(But alas i wont be getting any credit for finding the issue) And you are correct it can occur in strange circumstances but you never know when this circumstances arise.

> [@DavidTurner](#):
>
> . I opened a bug report here

Can I contribute to resolve this bug and make pull request for it?

And a big thanks for helping out.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 10, 2019, 12:40pm UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/16 "2019-04-10T12:40:28Z")

</div>

> [@Gaurav6141](#):
>
> But alas i wont be getting any credit for finding the issue

Apologies, I meant to link back to this thread but you beat me to it.

---

<div class="post-metadata">

**Author:** ![Gaurav6141](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@Gaurav6141](https://discuss.elastic.co/u/Gaurav6141)\
**Post date:** [April 10, 2019, 12:43pm UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/17 "2019-04-10T12:43:17Z")

</div>

Ok .. not any issue .. just a beginner in elastic Search.. Will soon be releasing a PR for it.

---

<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:** [May 8, 2019, 12:48pm UTC](https://discuss.elastic.co/t/primary-shards-unassigned-but-still-cluster-state-health-yellow/176189/18 "2019-05-08T12:48:06Z")

</div>

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