How to Check Cluster Health in Elasticsearch Quickly
To check cluster health in Elasticsearch, use the
GET /_cluster/health API endpoint. This returns the cluster status such as green, yellow, or red, indicating the overall health of your cluster.Syntax
The basic syntax to check cluster health is a simple HTTP GET request to the /_cluster/health endpoint. You can add optional parameters to filter or get detailed info.
GET /_cluster/health: Returns overall cluster health.GET /_cluster/health/{index}: Returns health for a specific index.- Optional query parameters include
level(cluster, indices, or shards) andtimeout.
http
GET /_cluster/health
# Optional parameters:
# level=cluster|indices|shards
# timeout=30sExample
This example shows how to check the overall cluster health using curl. The response includes the cluster status, number of nodes, and shard info.
bash
curl -X GET "localhost:9200/_cluster/health?pretty"Output
{
"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
}
Common Pitfalls
Common mistakes when checking cluster health include:
- Not specifying the correct Elasticsearch host or port, causing connection errors.
- Ignoring the
statusfield which showsgreen,yellow, orredstatus. - Assuming
yellowmeans failure; it means some replicas are not allocated but primary shards are fine. - Not using the
?prettyparameter for readable JSON output during manual checks.
bash
curl -X GET "localhost:9200/_cluster/health" # Wrong: Using wrong port or host curl -X GET "localhost:9201/_cluster/health" # Right: Correct host and port curl -X GET "localhost:9200/_cluster/health?pretty"
Quick Reference
| Parameter | Description | Example |
|---|---|---|
| GET /_cluster/health | Get overall cluster health | curl -X GET "localhost:9200/_cluster/health?pretty" |
| GET /_cluster/health/{index} | Get health for specific index | curl -X GET "localhost:9200/_cluster/health/my_index?pretty" |
| level | Detail level: cluster, indices, shards | GET /_cluster/health?level=indices |
| timeout | Wait time for response | GET /_cluster/health?timeout=30s |
Key Takeaways
Use the GET /_cluster/health API to quickly check Elasticsearch cluster status.
Cluster status can be green (healthy), yellow (some replicas unassigned), or red (issues).
Add ?pretty to the request URL for easier-to-read JSON output.
Check specific indices by adding the index name to the endpoint.
Ensure you connect to the correct Elasticsearch host and port to avoid errors.