# PrimaryShardNotAllocatedException: 主分片未分配

- **ID:** `elasticsearch/primary-shard-not-allocated`
- **领域:** elasticsearch
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| elasticsearch 8.9 | active | — | — |
| elasticsearch 8.10 | active | — | — |
| elasticsearch 7.17 | active | — | — |
| opensearch 2.7 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — If the allocation decider blocks (e.g., disk threshold), reroute is rejected; the underlying issue persists. (70% 失败率)
- **** — Data loss occurs; the problem is not diagnosed and may reappear for new indices. (95% 失败率)
- **** — Replicas require a primary shard first; increasing replicas does not help if primary is unallocated. (80% 失败率)
