The Cluster Health API helps you check the overall health and status of your Elasticsearch cluster quickly.
Cluster health API in Elasticsearch
Start learning this pattern below
Jump into concepts and practice - no test required
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.
Practice
Cluster Health API primarily provide?Solution
Step 1: Understand the purpose of Cluster Health API
The Cluster Health API is designed to report the health status of the Elasticsearch cluster, such as green, yellow, or red status.Step 2: Compare with other options
Options B, C, and D relate to documents, configuration, and performance, which are not the main focus of the Cluster Health API.Final Answer:
The current health status of the Elasticsearch cluster -> Option AQuick Check:
Cluster Health API = Cluster health status [OK]
- Confusing cluster health with document data
- Thinking it shows node configuration
- Assuming it reports query stats
Solution
Step 1: Recall the correct HTTP method and endpoint
The Cluster Health API uses the GET method with the endpoint/_cluster/health.Step 2: Eliminate incorrect options
POST is not used for this API, and the endpoint must be exactly/_cluster/health. Options C and D have wrong endpoints.Final Answer:
GET /_cluster/health -> Option AQuick Check:
GET + /_cluster/health = Correct syntax [OK]
- Using POST instead of GET
- Wrong endpoint like /_cluster/status
- Mixing endpoint parts
Solution
Step 1: Understand cluster health statuses
Green means all primary and replica shards are allocated properly, yellow means replicas missing but primaries allocated, red means some primaries missing.Step 2: Match the condition to status
Since all primary and replica shards are allocated, the status is green.Final Answer:
"status": "green" -> Option DQuick Check:
All shards allocated = green status [OK]
- Confusing yellow with green
- Thinking red means healthy
- Assuming blue is a valid status
GET /_cluster/health?level=shards but get an error. What is the likely cause?Solution
Step 1: Check valid values for
The Cluster Health API acceptslevelparameterlevelvalues like 'cluster', 'indices', and 'shards'. However, 'shards' is only supported in newer versions and may cause errors if unsupported.Step 2: Analyze other options
GET is correct method, endpoint is correct, anddetailis not a valid parameter for this API.Final Answer:
Thelevelparameter does not accept 'shards' as a value -> Option CQuick Check:
Invalid level value causes error [OK]
- Using POST instead of GET
- Wrong endpoint /_cluster/status
- Using invalid query parameters
Solution
Step 1: Identify the parameter for detailed index health
Thelevel=indicesparameter in the Cluster Health API returns health info for each index.Step 2: Compare with other options
level=clustergives overall cluster health only;/_cluster/stateand/_nodes/statsprovide different info unrelated to health per index.Final Answer:
GET /_cluster/health?level=indices -> Option BQuick Check:
Use level=indices for per-index health details [OK]
- Using level=cluster for detailed index info
- Confusing cluster state with health API
- Requesting node stats instead of health
