es运维常用命令
GET _search
{
“query”: {
“match_all”: {}
}
}
GET _cat/shards?v&s=state,index
1. 查看所有未分配的分片,确认 .watches 的状态
GET _cat/shards?v&s=state,index
2. 让 ES 解释为什么这个分片无法分配 (这是最关键的命令!)
GET _cluster/allocation/explain
{
“index”: “.watches”,
“shard”: 0,
“primary”: true
}
3. 检查集群健康状态和节点磁盘空间
GET _cluster/health
GET _cat/allocation?v
GET _cat/nodes?v&h=name,disk.total,disk.used,disk.avail,disk.used_percent
POST _cluster/reroute?retry_failed
{
“commands”: [
{
“allocate_empty_primary”: {
“index”: “.watches”, // 要修复的索引名
“shard”: 0, // 分片号,从 explain 输出中可知是 0
“node”: “3doFd3bZRyi1p8bcQ-CLmw”, // 选择任意一个节点的ID,例如第一个
“accept_data_loss”: true // 必须设置为 true,确认我们接受数据丢失
}
}
]
}
POST _cluster/reroute?retry_failed
{
“commands”: [
{
“allocate_empty_primary”: {
“index”: “.watches”,
“shard”: 0,
“node”: “3doFd3bZRyi1p8bcQ-CLmw”,
“accept_data_loss”: true
}
}
]
}
查看当前正在进行的分片恢复和迁移活动
GET _cat/recovery?active_only=true&detailed=true
实时查看集群中所有分片的状态(关注 RELOCATING 和 INITIALIZING 状态)
GET _cat/shards?v&h=index,shard,prirep,state,node,unassigned.reason&s=state
对正在迁移的分片使用此API。你需要知道分片的index, shard号, 和是primary还是replica。
GET _cluster/allocation/explain
{
“index”: “eds_forly_info_202506”,
“shard”: 0,
“primary”: true
}
GET _cluster/settings
{
}
GET _cluster/allocation/explain?pretty
GET _cluster/state/master_node,routing_table,blocks
POST /eds_forly_info_202411/_forcemerge?only_expunge_deletes=true
POST /eds_forly_info_202405/_forcemerge?only_expunge_deletes=true
POST /eds_forly_info_202406/_forcemerge?only_expunge_deletes=true
POST /eds_forly_info_202407/_forcemerge?only_expunge_deletes=true
GET eds_forly_info_202409/_search
POST /eds_forly_info_202501/_forcemerge?max_num_segments=1
POST /eds_forly_info_202501,eds_forly_info_202502,eds_forly_info_202503/_forcemerge?max_num_segments=1
POST /eds_forly_info_202505,eds_forly_info_202505,eds_forly_info_202506/_forcemerge?max_num_segments=1
POST /eds_forly_info_202507,eds_forly_info_202508,eds_forly_info_202509/_forcemerge?max_num_segments=1