The Cluster Health API helps you check the overall health and status of your Elasticsearch cluster quickly.
Cluster health API in Elasticsearch
GET /_cluster/health # Optional parameters: GET /_cluster/health?level=cluster|indices|shards GET /_cluster/health?wait_for_status=green|yellow|red&timeout=30s
Use GET /_cluster/health to get the overall cluster health.
You can add parameters like level to get more details or wait_for_status to wait until the cluster reaches a certain health.
GET /_cluster/health
GET /_cluster/health?level=indices
GET /_cluster/health?wait_for_status=green&timeout=30sThis Python program sends a request to the Cluster Health API and prints the cluster health details as JSON.
import requests # URL of your Elasticsearch cluster url = 'http://localhost:9200/_cluster/health' # Send GET request to Cluster Health API response = requests.get(url) # Print the JSON response print(response.json())
The cluster health status can be green (all good), yellow (some replicas not assigned), or red (some data missing).
Use the wait_for_status parameter to pause your request until the cluster reaches a desired health.
Checking cluster health regularly helps avoid surprises in your Elasticsearch setup.
The Cluster Health API shows the current health of your Elasticsearch cluster.
You can get overall or detailed health info using parameters.
It helps you monitor and keep your cluster running smoothly.