The cat.health API in Elasticsearch is an API endpoint used to retrieve the current health status of an Elasticsearch cluster. It provides key information about the cluster's health, helping operations personnel or system administrators understand and monitor the cluster's status.
When calling this API, you can obtain the following key metrics:
- cluster: The name of the cluster.
- status: The health status of the cluster, with possible values including green, yellow, and red. Green indicates all primary and replica shards are functioning properly; yellow indicates all primary shards are healthy but some replica shards are not correctly allocated; red indicates that some primary shards are not correctly allocated.
- node.total: The total number of nodes in the cluster.
- node.data: The number of nodes participating in data storage.
- shards: The total number of shards in the cluster.
- pri: The number of primary shards.
- relo: The number of shards currently being migrated.
- init: The number of shards currently being initialized.
- unassign: The number of unassigned shards.
- active_shards_percent: The percentage of active shards.
For example, if you want to check the health status of your Elasticsearch cluster, you can use the curl command to send an HTTP request to the cat.health API:
bashcurl -X GET "localhost:9200/_cat/health?v=true"
This will return output similar to the following format:
shellepoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks active_shards_percent 1604313681 12:34:41 elasticsearch yellow 5 5 20 10 2 0 5 0 93.3%
This output provides clear information, showing the cluster name is "elasticsearch", the status is "yellow", there are 5 nodes, 20 shards with 10 primary shards, 5 unassigned shards, and an active shards percentage of 93.3%.
By regularly monitoring these metrics, you can promptly identify and resolve potential issues within the cluster, ensuring stable operation.