When facing an abnormal health status (RED or YELLOW) in an Elasticsearch (ES) cluster, follow these steps to troubleshoot and resolve the issue:
Use the following command to get detailed cluster health information:
GET /_cluster/health?pretty
This will show the overall health status and the number of unassigned shards.
To identify which shards are unassigned, run:
GET /_cat/shards?v&h=index,shard,prirep,state,unassigned.reason&s=state
This command lists all shards, their state, and the reason for unassignment if applicable.
elasticsearch.yml.POST /_cluster/reroute?retry_failed=true
If shards are unassigned due to temporary issues, you can manually reassign them:
POST /_cluster/reroute
{
"commands": [
{
"allocate_stale_primary": {
"index": "your_index",
"shard": 0,
"node": "target_node",
"accept_data_loss": true
}
}
]
}
Note: Use accept_data_loss: true only if you are certain about the data loss.
If your cluster is RED due to unassigned primary shards, check the logs for errors. Suppose the issue is caused by insufficient nodes. Add a new node to the cluster and verify shard reassignment:
GET /_cluster/health?pretty
If the status changes to GREEN, the issue is resolved.
For enhanced monitoring and management of your ES cluster, consider using Tencent Cloud's Elasticsearch Service, which provides automated health monitoring, auto-scaling, and easy cluster management.