elasticsearch system_error ai_generated true

PrimaryShardNotAllocatedException: primary shard is not allocated

ID: elasticsearch/primary-shard-not-allocated

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-11-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
elasticsearch 8.9 active
elasticsearch 8.10 active
elasticsearch 7.17 active
opensearch 2.7 active

Root Cause

A primary shard cannot be assigned to any node due to allocation decider rules, disk space, or node failures.

generic

中文

由于分配决策规则、磁盘空间不足或节点故障,主分片无法分配到任何节点。

Official Documentation

https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-shards.html

Workarounds

  1. 90% success Check allocation explain: GET _cluster/allocation/explain?pretty and fix the root cause (e.g., free disk space, adjust routing allocation settings). Example: POST _cluster/settings { "persistent": { "cluster.routing.allocation.disk.watermark.low": "90%" } }
    Check allocation explain: GET _cluster/allocation/explain?pretty and fix the root cause (e.g., free disk space, adjust routing allocation settings). Example: POST _cluster/settings { "persistent": { "cluster.routing.allocation.disk.watermark.low": "90%" } }
  2. 80% success If due to node failure, re-enable allocation: PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } }
    If due to node failure, re-enable allocation: PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } }
  3. 75% success Manually allocate the shard to a specific node after verifying node health: POST _cluster/reroute { "commands": [ { "allocate_empty_primary": { "index": "my_index", "shard": 0, "node": "node-1", "accept_data_loss": true } } ] }
    Manually allocate the shard to a specific node after verifying node health: POST _cluster/reroute { "commands": [ { "allocate_empty_primary": { "index": "my_index", "shard": 0, "node": "node-1", "accept_data_loss": true } } ] }

中文步骤

  1. 使用_allocation/explain检查分配原因,并修复根本问题(如释放磁盘空间、调整路由设置)。
  2. 如果因节点故障导致,重新启用分配。
  3. 手动将分片分配到特定节点,需确认节点健康。

Dead Ends

Common approaches that don't work:

  1. 70% fail

    If the allocation decider blocks (e.g., disk threshold), reroute is rejected; the underlying issue persists.

  2. 95% fail

    Data loss occurs; the problem is not diagnosed and may reappear for new indices.

  3. 80% fail

    Replicas require a primary shard first; increasing replicas does not help if primary is unallocated.