0
0
ElasticsearchHow-ToBeginner · 3 min read

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) and timeout.
http
GET /_cluster/health

# Optional parameters:
# level=cluster|indices|shards
# timeout=30s
💻

Example

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 status field which shows green, yellow, or red status.
  • Assuming yellow means failure; it means some replicas are not allocated but primary shards are fine.
  • Not using the ?pretty parameter 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

ParameterDescriptionExample
GET /_cluster/healthGet overall cluster healthcurl -X GET "localhost:9200/_cluster/health?pretty"
GET /_cluster/health/{index}Get health for specific indexcurl -X GET "localhost:9200/_cluster/health/my_index?pretty"
levelDetail level: cluster, indices, shardsGET /_cluster/health?level=indices
timeoutWait time for responseGET /_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.