Elasticsearch _cluster/health

Elasticsearch’s cluster API is a good 30,000 ft high description of your cluster health. If you have Elasticsearch installed on your local machine, give this a try:

http://localhost:9200/_cluster/health

You output might look something like this:

{
“cluster_name”:   “elasticsearch”,
“status”:   “yellow”,
“timed_out”:  false,
“number_of_nodes”:  1,
“number_of_data_nodes”:  1,
“active_primary_shards”:  5,
“active_shards”:  5,
“relocating_shards”:  0,
“initializing_shards”:  0,
“unassigned_shards”:  5,
“delayed_unassigned_shards”:  0,
“number_of_pending_tasks”:  0,
“number_of_in_flight_fetch”:  0,
“task_max_waiting_in_queue_millis”:  0,
“active_shards_percent_as_number”:  50
}

Lets start off by talking about the traffic light status indicators of elastic. From their documentation:

Green : All primary and replica shards are allocated. Your cluster is 100% operational.

Yellow :All primary shards are allocated, but at least one replica is missing. No data is missing, so search results will still be complete. However, your high availability is compromised to some degree. If more shards disappear, you might lose data. Think of yellow as a warning that should prompt investigation.

Red: At least one primary shard (and all of its replicas) is missing. This means that you are missing data: searches will return partial results, and indexing into that shard will return an exception.

My local machine is clearly running on 5 shards and 0 replicas. The ‘active_primary_shards’ indicate how many primary shards you have in your cluster and the “active_shards” indicate the total number of shards you have in your cluster, this includes the number of replicas too. So if I had 1 (extra) replica for each shard, this number would be 10. That also explains why the cluster health is ‘yellow’, as the replicas are missing.

Here are the most important ones:

“cluster_name”: name the cluster

“status”: red | yellow | green – when each would occur is described above)

“timed_out”: true | false – was it able to reach the cluster

“number_of_nodes”: number of nodes in your cluster,

“number_of_data_nodes”: number of data nodes in your cluster (an ES cluster could have master and data nodes

“active_primary_shards”: explained above,

“active_shards”: explained above,

“relocating_shards”: shows the number of nodes moving from one node to another. When you add a node, ES might rebalance itself by moving shards and replicas to the new node. This value is generally 0

“initializing_shards”: this indicates the count of shards being freshly created. When a new index is being created, you might see the number here. But this should generally be 0. Even when the node is first created, you might see a number here as shards are loaded from disk.

“unassigned_shards”: Unassigned shards represent the number of unassigned replicas. In your local machine, you might see the same number as of primary shards, as you only have replicas.

Dive a level in by using this:

http://localhost:9200/_cluster/health?level=indices

This API gives you the current status of all indexes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s