elasticsearch-cluster-health
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDiagnose Cluster Health
诊断集群健康状态
Triage a non-green Elasticsearch cluster read-only: localize the problem, classify the allocation decider, and report
the single most likely cause with remediation. Never mutate cluster state — surface findings and let the operator act.
<!-- begin-partial: preamble -->对非绿色状态的Elasticsearch集群进行只读分类排查:定位问题、分类分配决策器,并报告最可能的问题原因及修复建议。切勿修改集群状态——仅呈现排查结果,由操作员执行操作。
<!-- begin-partial: preamble -->Environment Configuration
环境配置
This skill executes Elasticsearch operations through the CLI. If the
CLI is not installed, tell the user what it is needed for. Do
not guess credentials, call the HTTP API directly, or attempt other workarounds.
elasticelasticThis skill references operations in HTTP-shorthand form (e.g., , , ,
, ). The Operations table at the end of this document
maps each shorthand to the equivalent CLI command — always use the CLI rather than calling the HTTP API
directly.
<!-- end-partial: preamble -->GET /GET /_cat/indicesGET /{index}/_mappingGET /{index}/_settings/index.modePOST /_queryelastic本技能通过 CLI执行Elasticsearch操作。如果未安装 CLI,请告知用户其用途。请勿猜测凭证、直接调用HTTP API或尝试其他变通方法。
elasticelastic本技能使用HTTP简写形式引用操作(例如:、、、、)。本文档末尾的操作表格将每个简写映射为对应的 CLI命令——请始终使用CLI而非直接调用HTTP API。
<!-- end-partial: preamble -->GET /GET /_cat/indicesGET /{index}/_mappingGET /{index}/_settings/index.modePOST /_queryelasticProcess
流程
-
Read the overall status. Call. The
GET /_cluster/healthfield is the verdict:status- — every primary and replica is assigned. Report healthy and stop.
green - — every primary is assigned but at least one replica is not. Data remains readable; redundancy is degraded. This is not data loss.
yellow - — at least one primary is unassigned. Data for that shard is unavailable; treat as urgent.
red
Also read,unassigned_shards, andinitializing_shards. The decision: continue only when status is yellow or red. Ifrelocating_shardsandinitializing_shards > 0, the cluster is recovering on its own — callunassigned_shards == 0to confirm progress, wait, and re-checkGET /_cat/recoverybefore escalating.GET /_cluster/healthData needed: cluster-wideand shard counters.status -
Localize the problem to one index. Calland pick the index that drives the cluster-wide status:
GET /_cluster/health?level=indices- Any red index outranks every yellow index.
- Among reds or yellows, prefer the index with the most .
unassigned_shards - A red system index (,
.security,.kibana*) outranks application indices because the rest of the stack depends on it..fleet-*
Optionally callto list every unassigned shard on that index and see whether failures are primaries (GET /_cat/shards/{index}?h=index,shard,prirep,state,unassigned.reason) or replicas (prirep=p).prirep=rThe decision: focus the next steps on exactly one index — the one whose recovery unblocks the cluster.Data needed: per-indexandstatus; shard role (primary vs replica) when available.unassigned_shards -
Separate trigger from root cause. Callwith no body so Elasticsearch selects an unassigned shard, or target the worst shard explicitly:
POST /_cluster/allocation/explainjson{ "index": "<index>", "shard": <id>, "primary": <true|false> }Read these fields in order:- —
primarymeans a replica is unassigned (typical yellow);falsemeans a primary is unassigned (typical red).true - — top-level allocation verdict (
can_allocate,no,yes,throttled, …).no_valid_shard_copy - — what triggered reassignment (e.g.
unassigned_info.reason,NODE_LEFT). This is not the root cause whenINDEX_CREATEDiscan_allocate; it only explains why the shard became unassigned.no - — human-readable summary; quote it verbatim in the report.
allocate_explanation - — per-node decider results. Find deciders with
node_allocation_decisions[].deciders[]; the decider name (e.g.decision: "NO",disk_threshold,filter) is the root cause class.awareness
The decision:- Yellow + — impact is limited to replica redundancy; no data loss. Continue to step 4 to name the blocking decider (do not stop at
primary: false).NODE_LEFT - Red + — data for that shard is missing. Continue to step 4; if
primary: trueiscan_allocate, treat as potential data loss immediately.no_valid_shard_copy
Data needed: allocation-explain response for one representative unassigned shard on the chosen index. -
Classify the decider. Map the blocking signal to a cause class. Prefer the decider withover the
decision: "NO"trigger.unassigned_info.reasonSignal Cause class Typical remediation (operator applies) ,decider: disk_thresholddecision: NODisk high/low watermark exceeded Free disk on the named node, add data-node capacity, or adjust after confirming usage viacluster.routing.allocation.disk.watermark.*GET /_cat/allocationordecider: filter,decider: awarenessdecision: NOAllocation filtering or zone awareness Add a node that satisfies / awareness attributes, or adjust index/cluster allocation settingsindex.routing.allocation.*or recovery in progressdecider: throttlingTransient recovery Wait; monitor and re-checkGET /_cat/recoveryGET /_cluster/health(often with emptycan_allocate: no_valid_shard_copy)node_allocation_decisionsNo surviving shard copy See step 5 — data loss scenario but shard still unassignedcan_allocate: yesDelayed allocation or cluster state catch-up Check delay; wait and re-checkunassigned_info.atFor disk pressure (common yellow scenario after): replicas relocate to remaining nodes; if a survivor is above the high watermark (NODE_LEFT, default 90%), thecluster.routing.allocation.disk.watermark.highdecider blocks replica allocation even though primaries stay assigned. The fix is disk capacity or watermark relief — not deleting the index or forcing an empty primary.disk_thresholdData needed: decider name,text, and affected node names fromexplanation.node_allocation_decisions -
Recommend remediation — read-only triage ends here. Report the single most likely cause (decider class + verbatim) and one primary remediation path. Match urgency to color and shard role.
allocate_explanationYellow / replica unassigned (no data loss):- State clearly: all primaries are assigned; only replicas are missing; no data loss.
- Name the real decider (e.g. disk high watermark on ), not merely “a node left”.
es-node-2 - Recommend: free disk space, expand storage, add data nodes, or adjust disk watermarks after reviewing
.
GET /_cat/allocation - Do not recommend: deleting the index, , force-allocating over a healthy primary, or restarting the entire cluster without evidence.
allocate_empty_primary
Red / primary unassigned with(data loss risk):no_valid_shard_copy- State clearly: a primary shard is unassigned; queries/routing for that shard fail; treat as urgent and localized to the named index.
- Explain: the only copy was on the departed node; Elasticsearch cannot allocate a primary because no valid copy
exists on any remaining node ().
can_allocate: no_valid_shard_copy - Recovery paths in order:
- Bring the departed node back if its data directory is intact — the shard copy returns.
- Restore from snapshot into the index (or a new index followed by reindex) when snapshots exist.
- Last resort only: with
POST /_cluster/reroute— this creates an empty primary and permanently loses all documents on that shard. State data loss explicitly; never present this as the first or casual fix.allocate_empty_primary
- Do not recommend: deleting the index without discussing data loss, or without the data-loss warning.
allocate_empty_primary
Self-healing in progress:- When deciders show throttling or active peer recovery, recommend waiting and re-checking read-only APIs above.
Do not execute reroutes, snapshot restores, or settings changes — surface cause and remediation only.
-
读取整体状态。调用。
GET /_cluster/health字段是判断依据:status- —— 所有主分片和副本分片均已分配。报告集群健康并停止操作。
green - —— 所有主分片已分配,但至少有一个副本分片未分配。数据仍可读取;冗余性下降。这不属于数据丢失。
yellow - —— 至少有一个主分片未分配。该分片的数据不可用;需视为紧急情况。
red
同时读取、unassigned_shards和initializing_shards字段。决策逻辑:仅当状态为黄色或红色时继续排查。如果relocating_shards且initializing_shards > 0,说明集群正在自行恢复——调用unassigned_shards == 0确认进度,等待后重新调用GET /_cat/recovery再判断是否需要升级处理。GET /_cluster/health所需数据:集群级别的和分片统计数据。status -
将问题定位到单个索引。调用,选择影响集群整体状态的索引:
GET /_cluster/health?level=indices- 任何红色状态的索引优先级高于黄色状态的索引。
- 在红色或黄色状态的索引中,优先选择数量最多的索引。
unassigned_shards - 红色状态的系统索引(、
.security、.kibana*)优先级高于业务索引,因为整个技术栈依赖这些系统索引。.fleet-*
可选择性调用,列出该索引下所有未分配的分片,查看失败的是主分片(GET /_cat/shards/{index}?h=index,shard,prirep,state,unassigned.reason)还是副本分片(prirep=p)。prirep=r决策逻辑:将后续步骤的焦点完全集中在一个索引上——恢复该索引即可解除集群阻塞。所需数据:各索引的和status;分片角色(主分片/副本分片,如有)。unassigned_shards -
区分触发事件与根本原因。调用不带请求体的,让Elasticsearch自动选择一个未分配分片;或明确指定问题最严重的分片:
POST /_cluster/allocation/explainjson{ "index": "<index>", "shard": <id>, "primary": <true|false> }按顺序读取以下字段:- ——
primary表示副本分片未分配(典型黄色状态场景);false表示主分片未分配(典型红色状态场景)。true - —— 顶级分配决策结果(
can_allocate、no、yes、throttled等)。no_valid_shard_copy - —— 触发重新分配的事件(例如
unassigned_info.reason、NODE_LEFT)。当INDEX_CREATED为can_allocate时,这不是根本原因;它仅解释分片为何变为未分配状态。no - —— 人类可读的摘要;在报告中直接引用原文。
allocate_explanation - —— 各节点的决策器结果。找到
node_allocation_decisions[].deciders[]的决策器;决策器名称(例如decision: "NO"、disk_threshold、filter)即为根本原因类别。awareness
决策逻辑:- 黄色状态 + —— 影响仅限于副本冗余;无数据丢失。继续执行步骤4以确定阻塞的决策器(切勿在
primary: false处停止排查)。NODE_LEFT - 红色状态 + —— 该分片的数据丢失。继续执行步骤4;如果
primary: true为can_allocate,需立即视为潜在数据丢失场景。no_valid_shard_copy
所需数据:所选索引上一个代表性未分配分片的分配解释响应。 -
分类决策器。将阻塞信号映射到原因类别。优先选择的决策器,而非
decision: "NO"中的触发事件。unassigned_info.reason信号 原因类别 典型修复方案(由操作员执行) ,decider: disk_thresholddecision: NO磁盘高低水位线超出阈值 在指定节点释放磁盘空间、添加数据节点容量,或通过 确认使用情况后调整GET /_cat/allocation参数cluster.routing.allocation.disk.watermark.*或decider: filter,decider: awarenessdecision: NO分配过滤或区域感知 添加满足 /感知属性的节点,或调整索引/集群的分配设置index.routing.allocation.*或恢复正在进行中decider: throttling临时恢复 等待;通过 监控进度,并重新调用GET /_cat/recovery检查状态GET /_cluster/health(通常伴随空的can_allocate: no_valid_shard_copy)node_allocation_decisions无存活分片副本 查看步骤5 —— 数据丢失场景 但分片仍未分配can_allocate: yes延迟分配或集群状态同步延迟 检查 延迟时间;等待后重新检查unassigned_info.at对于磁盘压力(后的常见黄色状态场景):副本分片会迁移到剩余节点;如果某个存活节点的磁盘使用率超过高水位线(NODE_LEFT,默认90%),cluster.routing.allocation.disk.watermark.high决策器会阻止副本分片分配,即使主分片仍处于已分配状态。修复方案是增加磁盘容量或调整水位线——不要删除索引或强制分配空主分片。disk_threshold所需数据:决策器名称、文本,以及explanation中的受影响节点名称。node_allocation_decisions -
推荐修复方案——只读分类排查到此结束。报告最可能的单一原因(决策器类别 + 原文引用的)和一条主要修复路径。根据状态颜色和分片角色匹配紧急程度。
allocate_explanation黄色状态 / 副本分片未分配(无数据丢失):- 明确说明:所有主分片均已分配;仅副本分片缺失;无数据丢失。
- 指明真正的决策器原因(例如节点磁盘高水位线超出),而非仅提及“节点离开”。
es-node-2 - 推荐方案:释放磁盘空间、扩展存储、添加数据节点,或查看后调整磁盘水位线。
GET /_cat/allocation - 不推荐:删除索引、执行、在健康主分片上强制分配,或无证据地重启整个集群。
allocate_empty_primary
红色状态 / 主分片未分配且(存在数据丢失风险):no_valid_shard_copy- 明确说明:主分片未分配;该分片的查询/路由失败;需视为紧急情况,且问题局限于指定索引。
- 解释:该分片的唯一副本位于已下线的节点;Elasticsearch无法分配主分片,因为剩余节点上没有有效的副本()。
can_allocate: no_valid_shard_copy - 恢复路径优先级:
- 恢复下线节点(如果其数据目录完好)——分片副本将恢复。
- 从快照恢复到该索引(或恢复到新索引后重新索引)(如果存在快照)。
- 仅作为最后手段: 执行并使用
POST /_cluster/reroute—— 这会创建空主分片并永久丢失该分片上的所有文档。需明确说明数据丢失风险;切勿将此作为首选或随意的修复方案。allocate_empty_primary
- 不推荐:未讨论数据丢失风险就删除索引,或未给出数据丢失警告就执行。
allocate_empty_primary
集群正在自行恢复:- 当决策器显示限流或对等恢复正在进行时,建议等待并重新调用上述只读API检查状态。
请勿执行路由调整、快照恢复或设置更改——仅呈现问题原因和修复建议。
Guidelines
指导原则
- Read-only: Use only GET/POST explain APIs for triage. Remediation is advice; the operator performs writes.
- Trigger ≠ cause: explains the event;
unassigned_info.reason: NODE_LEFTdeciders explain why allocation still fails.node_allocation_decisions - Replica vs primary: Yellow + = redundancy gap, not data loss. Red +
primary: false= missing data for that shard.primary: true - One index, one cause: Pick the highest-impact index and the strongest NO decider; avoid listing every shard.
- Cat helpers: Use for disk percentages per node and
GET /_cat/allocationfor ongoing recoveries when the decider class is unclear or recovery is in progress.GET /_cat/recovery
- 只读操作: 仅使用GET/POST解释API进行分类排查。修复方案仅为建议;由操作员执行写入操作。
- 触发事件 ≠ 根本原因: 解释了事件本身;
unassigned_info.reason: NODE_LEFT中的决策器解释了分配仍失败的原因。node_allocation_decisions - 副本与主分片的区别: 黄色状态 + = 冗余缺口,而非数据丢失。红色状态 +
primary: false= 该分片的数据丢失。primary: true - 单一索引,单一原因: 选择影响最大的索引和最明确的NO决策器;避免列出所有分片。
- Cat工具辅助: 当决策器类别不明确或恢复正在进行时,使用查看各节点磁盘使用率,使用
GET /_cat/allocation监控正在进行的恢复操作。GET /_cat/recovery
Examples
示例
Yellow — disk watermark after node departure. Health shows yellow with unassigned replicas on .
Allocation explain returns , , but decider NO on
(“above the high watermark … 90%”). Report: no data loss; root cause is disk pressure on the receiving node;
remediate disk/watermark — not “node left” alone.
logs-2025-07primary: falseunassigned_info.reason: NODE_LEFTdisk_thresholdes-node-2Red — primary with no valid copy. Health shows red on with one unassigned shard. Explain returns
, , . Report: urgent;
primary data missing; restore node or snapshot; mention only as last resort with explicit data
loss.
orders-2025primary: truecan_allocate: no_valid_shard_copylast_allocation_status: no_valid_shard_copyallocate_empty_primary黄色状态 —— 节点下线后磁盘水位线超出。集群健康状态显示黄色,索引存在未分配副本。分配解释返回、,但节点的决策器返回NO(“超出高水位线……90%”)。报告内容:无数据丢失;根本原因是接收节点的磁盘压力;修复方案为释放磁盘空间或调整水位线——而非仅提及“节点离开”。
logs-2025-07primary: falseunassigned_info.reason: NODE_LEFTes-node-2disk_threshold红色状态 —— 主分片无有效副本。集群健康状态显示索引为红色,存在一个未分配分片。分配解释返回、、。报告内容:紧急情况;主分片数据丢失;恢复节点或从快照恢复;仅在最后手段时提及并明确说明数据丢失风险。
orders-2025primary: truecan_allocate: no_valid_shard_copylast_allocation_status: no_valid_shard_copyallocate_empty_primaryOperations
操作
| HTTP API (shorthand) | |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| HTTP API(简写形式) | |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |