Elasticsearch Elasticsearch cluster health

By Opster Team

Updated: Jun 7, 2023

| 2 min read

Understanding Elasticsearch Cluster Health

What is Elasticsearch cluster health?

Elasticsearch cluster health is an essential metric to monitor, as it provides insights into the overall status and performance of your cluster.

This article will discuss the key aspects of cluster health, how to interpret the health status, and steps to improve it.

Key Aspects of Cluster Health

1. Health Status: The health status of an Elasticsearch cluster can be green, yellow, or red. A green status indicates that all primary and replica shards are allocated, while a yellow status means that all primary shards are allocated, but one or more replica shards are not. A red status indicates that one or more primary shards are not allocated.

2. Active Primary Shards: The number of active primary shards in the cluster. These shards hold the actual data and are responsible for indexing and search operations.

3. Active Shards: The total number of active shards in the cluster, including both primary and replica shards.

4. Unassigned Shards: The number of shards that are not allocated to any node in the cluster. Unassigned shards can occur due to node failures, insufficient resources, or configuration issues.

5. Initializing Shards: The number of shards that are currently being initialized, either during cluster startup or after a node failure.

6. Relocating Shards: The number of shards that are being moved from one node to another, typically to balance the load across the cluster.

Interpreting Cluster Health

To check the health status of your Elasticsearch cluster, you can use the Cluster Health API:

GET /_cluster/health

The API response will provide the health status, along with other key metrics:

{
  "cluster_name": "my_cluster",
  "status": "green",
  "timed_out": false,
  "number_of_nodes": 3,
  "number_of_data_nodes": 3,
  "active_primary_shards": 10,
  "active_shards": 20,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 0,
  "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": 100.0
}

Improving Cluster Health

If your cluster health status is yellow or red, consider the following steps to improve it:

1. Add more nodes: Increasing the number of nodes in your cluster can help distribute the load and allocate unassigned shards.

2. Adjust shard allocation settings: Review and update the shard allocation settings to ensure that shards are evenly distributed across the cluster.

3. Check for hardware issues: Inspect the hardware of your nodes to identify and resolve any issues that may be causing shard allocation failures.

4. Review index settings: Ensure that the number of replicas is set appropriately for your cluster size and use case.

5. Monitor logs and metrics: Regularly review Elasticsearch logs and metrics to identify potential issues and take corrective actions.

Conclusion 

By monitoring and maintaining the health of your Elasticsearch cluster, you can ensure optimal performance and avoid potential issues that may impact your search and analytics