What's Actually Happening

Elasticsearch shards are in FAILED state and cannot be allocated.

The Error You'll See

```bash $ curl localhost:9200/_cat/shards?v

index shard prirep state docs store ip myindex 0 p FAILED myindex 1 r UNASSIGNED ```

Why This Happens

  1. 1.Node failure - Node holding shard left cluster
  2. 2.Corrupted shard - Shard data corrupted
  3. 3.Disk full - No space for shard allocation
  4. 4.Allocation deciders - Rules preventing allocation

Step 1: Check Shard Explanation

bash
# Get allocation explanation:
curl -XGET 'localhost:9200/_cluster/allocation/explain?pretty' -d '{
  "index": "myindex",
  "shard": 0,
  "primary": true
}'

Step 2: Reroute Shard

bash
# Reroute failed shard:
curl -XPOST 'localhost:9200/_cluster/reroute?pretty' -d '{
  "commands": [{
    "allocate_stale_primary": {
      "index": "myindex",
      "shard": 0,
      "node": "node-1",
      "accept_data_loss": true
    }
  }]
}'

Step 3: Check Disk Space

bash
# Check disk per node:
curl localhost:9200/_cat/allocation?v

Step 4: Restore from Snapshot

bash
# Restore index:
curl -XPOST 'localhost:9200/_snapshot/mybackup/snap1/_restore' -d '{
  "indices": "myindex"
}'

Elasticsearch Shard Checklist

CheckCommandExpected
Shard state_cat/shardsSTARTED
Allocation_cluster/allocationPossible
Disk space_cat/allocationAvailable

Verify the Fix

bash
curl localhost:9200/_cat/shards/myindex?v
# Output: All shards STARTED
  • [Fix Elasticsearch Cluster Red Status](/articles/fix-elasticsearch-cluster-red-status)
  • [Fix Elasticsearch Index Readonly](/articles/fix-elasticsearch-index-readonly)