# PrimaryShardNotAllocatedException: primary shard is not allocated

- **ID:** `elasticsearch/primary-shard-not-allocated`
- **Domain:** elasticsearch
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| elasticsearch 8.9 | active | — | — |
| elasticsearch 8.10 | active | — | — |
| elasticsearch 7.17 | active | — | — |
| opensearch 2.7 | active | — | — |

## Workarounds

1. **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%" } }** (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%" } }
   ```
2. **If due to node failure, re-enable allocation: PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } }** (80% success)
   ```
   If due to node failure, re-enable allocation: PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } }
   ```
3. **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 } } ] }** (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 } } ] }
   ```

## Dead Ends

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