📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

以紧凑的表格形式返回集群健康状态信息。

API 格式 #

GET /_cat/health

API 作用 #

该 API 以表格形式返回集群健康状态:

  • 显示集群名称和健康状态
  • 显示节点数量(总节点和数据节点)
  • 显示分片统计信息
  • 显示待处理任务信息
  • 显示活跃分片百分比

API 参数 #

查询参数 #

参数类型是否必填默认值描述
formatString文本表格响应格式(如 jsonyaml
hString所有列逗号分隔的列名列表
vBooleanfalse是否显示列标题
tsBooleantrue是否显示时间戳列
sString-排序方式(格式:列名:asc列名:desc

集群健康参数 #

参数类型是否必填默认值描述
levelStringcluster详细程度:clusterindicesshards
timeoutTime30s操作超时时间
wait_for_statusString-等待指定健康状态:greenyellowred
wait_for_no_relocating_shardsBooleanfalse等待直到没有重定位分片
wait_for_no_initializing_shardsBooleanfalse等待直到没有初始化中的分片
wait_for_active_shardsString-等待指定数量的活跃分片(如 all1
wait_for_nodesString-等待指定数量的节点(如 5>5<5

响应列说明 #

列名别名描述
clustercl集群名称
statusst健康状态(green/yellow/red)
node.totalnt, nodeTotal节点总数
node.datand, nodeData可存储数据的节点数
shardst, sh, shardsTotal分片总数
prip, shardsPrimary主分片数
relor, shardsRelocating重定位中的分片数
initi, shardsInitializing初始化中的分片数
unassignu, shardsUnassigned未分配的分片数
pending_taskspt, pendingTasks待处理任务数
max_task_wait_timemtwt, maxTaskWaitTime最长任务等待时间
active_shards_percentasp, activeShardsPercent活跃分片百分比
timestamp-响应时间戳

请求示例 #

查询集群健康 #

GET /_cat/health?v

JSON 格式 #

GET /_cat/health?format=json

选择显示列 #

GET /_cat/health?h=cluster,status,node.total,shards&v

等待绿色状态 #

GET /_cat/health?wait_for_status=green&timeout=1m

响应示例 #

文本表格格式(verbose 模式) #

timestamp             cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
2026-02-04 12:00:00   my-cluster green   3          3         15     5    0     0            0                  -                       100.0%

JSON 格式 #

[
  {
    "cluster": "my-cluster",
    "status": "green",
    "node.total": "3",
    "node.data": "3",
    "shards": "15",
    "pri": "5",
    "relo": "0",
    "init": "0",
    "unassign": "0",
    "pending_tasks": "0",
    "max_task_wait_time": null,
    "active_shards_percent": "100.0%",
    "timestamp": "2026-02-04T12:00:00Z"
  }
]

黄色状态示例 #

timestamp             cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
2026-02-04 12:00:00   my-cluster yellow   3          3         15     5    0     1     1               2                  5s                      93.3%

健康状态说明 #

状态描述
green所有主分片和副本分片都已分配
yellow所有主分片已分配,但有部分副本分片未分配
red有部分主分片未分配

使用场景 #

  1. 健康监控:快速查看集群健康状态
  2. 故障排查:检查未分配的分片和待处理任务
  3. 容量规划:查看节点和分片分布
  4. 状态等待:等待集群达到特定健康状态

注意事项 #

  1. v 参数:使用 ?v 显示列标题
  2. 时间戳:时间戳自动添加到所有响应
  3. 等待参数:等待参数会阻塞请求直到条件满足
  4. 对齐方式:数值列自动右对齐

相关操作 #

  • GET /_cluster/health:获取详细健康信息
  • GET /_cat/nodes:查询节点信息
  • GET /_cat/shards:查询分片信息
  • GET /_cat/allocation:查询分片分配解释

实现文件 #

  • REST 处理器RestHealthAction.java
  • 基础类AbstractCatAction.java