5

I'm working on an application that creates N indices and N aliases, and there's a one-to-one correspondence between these indices and aliases.

But once in a while, I instead get N indices and N-1 aliases, and one of the indices has a name that should've been used by an alias. For some reason when this happens, the bogus index-that-should-have-been-an-alias-name has a yellow status, while the other indices are all green.

What might cause an index to be the only one that is yellow? I'm hoping understanding this might help me narrow down which part of the code I need to scrutinize to fix the bug.

My elasticsearch.yml has just:

cluster.name: "docker-cluster"
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["127.0.0.1", "[::1]"]

In production we may have more ES nodes, but this is just a test system, so just one ES node.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
dstromberg
  • 6,954
  • 1
  • 26
  • 27
  • 1
    https://stackoverflow.com/a/60602968/4039431 this answer explained in detail the cause of yellow status, how to fix it and what is the impact of it, please have a look and let me know if further questions – Amit Mar 24 '20 at 02:25

2 Answers2

9

The status "yellow" indicates that replica shards of that certain index could not get allocated to other nodes.

This can happen for various reasons. For example, you have specified more replicas than you have nodes. It depends on your cluster setup and whether you configured shard allocation by your own or not.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
apt-get_install_skill
  • 2,818
  • 10
  • 27
  • 1
    1 common reason is if you are running Elasticsearch with only 1 node, like when running Elasticsearch on local in a Docker container, and you only have 1 container. Elasticsearch will not make that node/container a replica, so your indices would always be yellow. – Gino Mempin Jul 08 '23 at 03:05
  • Related section of the doc: https://www.elastic.co/guide/en/elasticsearch/reference/8.4/cluster-health.html#cluster-health-api-desc: "*yellow means that the primary shard is allocated but replicas are not*" – Gino Mempin Jul 08 '23 at 03:11
2

Elasticsearch will never assign a replica to the same node as the primary shard, so if you only have one node it is perfectly normal and expected for your cluster to indicate yellow. If you feel better about it being green, then change the number of replicas on each index to be 0.

PUT /my-index/_settings
{
    "index" : {
        "number_of_replicas" : 0
    }
}

Please read this blog https://opster.com/guides/elasticsearch/operations/elasticsearch-yellow-status/

It explains very well how to fix yellow indexes.

Gravity API
  • 680
  • 8
  • 16
  • 1
    Rather than "_If you feel better about it being green_", it should be "_If you understand the risks and implications_". – Gino Mempin Jul 07 '23 at 00:43