How to fix ShardNotFoundException: no shard available for search in Elasticsearch

ElasticsearchINTERMEDIATEHIGHUpdated Dec 29, 2025· 213 views

This error occurs when Elasticsearch cannot find any available shard replica to execute a search query, typically due to unassigned shards from node failures, cluster rebalancing, or misconfigured replication settings. Resolving shard allocation issues restores search functionality.

Quick fix

Fixes ShardNotFoundException: no shard available for search

curl -X GET "localhost:9200/_cluster/health?pretty"
  1. Check cluster health and identify unassigned shards
  2. Use cluster allocation explain API for detailed diagnosis
  3. Verify shard allocation is enabled
  4. Scale up your cluster or reduce replicas
elasticsearch — error
curl -X GET "localhost:9200/_cluster/health?pretty"
ShardNotFoundException: no shard available for search

What this error means

This exception means Elasticsearch attempted to execute your search query but found no available copies of the required shard to query against. Every index in Elasticsearch is divided into shards, and each shard can have multiple replicas. When a search comes in, Elasticsearch must route it to one of these shard copies. If all shard copies are unavailable—because nodes hosting them crashed, network connectivity is broken, or the cluster hasn't finished rebalancing—the search request cannot proceed. This differs from a missing index; the index exists, but the data isn't accessible on any node. The error indicates a shard allocation problem, not a programming bug in your query.

Typical symptoms

  • Search requests fail with "ShardNotFoundException: no shard available for search"
  • GET requests to /_cluster/health show yellow or red status
  • Some indices return 0 results while similar queries worked before
  • Cluster status is red when checking /_cluster/health (indicates missing primary shards)
  • Partial search results with some shards succeeding and others timing out
  • GET requests to /_cat/shards show shards in UNASSIGNED state
  • Error includes text like "[[index_name][shard_number]]" indicating which shard failed

Common causes

  1. Node hosting a shard replica crashed or left the cluster ungracefully
  2. Network partition isolates nodes so the cluster loses connectivity with shard replicas
  3. Insufficient disk space on data nodes prevents shard allocation
  4. Cluster rebalancing is in progress after a node was added or removed
  5. Replica count is higher than available nodes (e.g., 2 replicas but only 1 node in cluster)
  6. Shards failed to initialize due to corruption or misconfiguration during cluster startup
  7. Shard allocation is disabled (check cluster.routing.allocation.enable setting)
  8. Rolling restart or maintenance left shards unassigned and not recovered

How to fix "ShardNotFoundException: no shard available for search"

1Check cluster health and identify unassigned shards

Use the cluster health API to see the overall status:

bash
curl -X GET "localhost:9200/_cluster/health?pretty"

Look at the response:
- status: red (primary shards missing), yellow (replicas missing), or green (all OK)
- unassigned_shards: count of shards not allocated to any node
- active_shards_percent_as_number: percentage of active shards

Then view detailed shard status:

bash
curl -X GET "localhost:9200/_cat/shards?v"

Find shards with state UNASSIGNED and note the index and shard number.

2Use cluster allocation explain API for detailed diagnosis

This API reveals exactly why a shard is unassigned:

bash
curl -X GET "localhost:9200/_cluster/allocation/explain?pretty" \
  -H 'Content-Type: application/json' \
  -d '{
    "index": "your_index_name",
    "shard": 0,
    "primary": true
  }'

The response includes:
- can_allocate: whether the shard can be assigned
- allocate_explanation: human-readable reason (e.g., "no nodes available after filtering")
- unassigned_info: reason shard became unassigned (e.g., NODE_LEFT, CLUSTER_RECOVERED)

Common reasons:
- "node does not meet allocation deciders" — incompatible disk/memory
- "no nodes available after filtering" — insufficient replicas for configured count
- "cannot allocate to same node as another copy" — all eligible nodes are taken

3Verify shard allocation is enabled

Check if shard allocation has been disabled (common during rolling restarts):

bash
curl -X GET "localhost:9200/_cluster/settings?pretty"

Look for cluster.routing.allocation.enable setting. If it is set to "none" or "primaries", enable it:

bash
curl -X PUT "localhost:9200/_cluster/settings" \
  -H 'Content-Type: application/json' \
  -d '{
    "persistent": {
      "cluster.routing.allocation.enable": "all"
    }
  }'

Wait a few seconds and check cluster health again. Shards should begin allocating.

4Scale up your cluster or reduce replicas

If you have more replicas configured than available nodes, replicas cannot allocate.

Check current settings:

bash
curl -X GET "localhost:9200/your_index_name/_settings?pretty"

Look for number_of_replicas. If you have fewer nodes than replicas + 1 (primary), reduce replicas:

bash
curl -X PUT "localhost:9200/your_index_name/_settings" \
  -H 'Content-Type: application/json' \
  -d '{
    "index": {
      "number_of_replicas": 0
    }
  }'

For production, the better long-term fix is to add more nodes to your cluster so replicas can spread across them for redundancy.

5Check disk space and memory on all nodes

Elasticsearch will not allocate shards to nodes running low on disk or memory:

bash
curl -X GET "localhost:9200/_nodes/stats/fs,jvm?pretty"

Look at each node's:
- fs.available_in_bytes: free disk space
- jvm.mem.heap_used_percent: heap memory pressure

If disk is near capacity, either:
1. Delete old indices: curl -X DELETE "localhost:9200/old_index"
2. Add more disk space to the node
3. Increase the low disk watermark thresholds (advanced; not recommended long-term)

If heap is full, increase Xmx in elasticsearch.yml and restart the node.

6Force allocate unassigned primary shards (last resort)

If you have data loss and need to force allocation of unassigned primary shards (risky—may cause inconsistency):

bash
curl -X POST "localhost:9200/_cluster/reroute" \
  -H 'Content-Type: application/json' \
  -d '{
    "commands": [{
      "allocate_stale_primary": {
        "index": "your_index_name",
        "shard": 0,
        "node": "node_id"
      }
    }]
  }'

Only do this if: Primary shard data is lost, all replicas are gone, and you accept potential data inconsistency. This should never be done in production without careful analysis.

Check node IDs with:

bash
curl -X GET "localhost:9200/_cat/nodes?v"
7Monitor recovery and wait for green status

After making changes, monitor the cluster as shards reallocate:

bash
curl -X GET "localhost:9200/_cluster/health?wait_for_status=green&timeout=5m&pretty"

This waits up to 5 minutes for the cluster to reach green status. Watch the logs:

bash
tail -f /var/log/elasticsearch/elasticsearch.log | grep -i "allocation"

You'll see messages like "completed allocation of shard [index_name][0]". Once status is green and unassigned_shards is 0, your searches should work again.

Advanced notes

Snapshot recovery: If nodes are permanently lost, restore from a snapshot: curl -X POST "localhost:9200/_snapshot/repo_name/snapshot_name/_restore". Shard filtering: Use allocation awareness to pin shards to specific nodes with rack/zone awareness. Index replicas per node: Use index.routing.allocation.max_retries_per_shard to retry allocation; default is 5. Circuit breaker: If you see frequent "no shard available" during heavy indexing, the circuit breaker may be rejecting operations—check indices.breaker.total.limit. Read preferences: Use preference=_local in search queries to only query local shards if available, falling back to other nodes.

Frequently asked questions

What does "ShardNotFoundException: no shard available for search" mean?
This exception means Elasticsearch attempted to execute your search query but found no available copies of the required shard to query against. Every index in Elasticsearch is divided into shards, and each shard can have multiple replicas. When a search comes in, Elasticsearch must route it to one of these shard copies.
How do I fix "ShardNotFoundException: no shard available for search"?
This error occurs when Elasticsearch cannot find any available shard replica to execute a search query, typically due to unassigned shards from node failures, cluster rebalancing, or misconfigured replication settings. Resolving shard allocation issues restores search functionality.
What causes "ShardNotFoundException: no shard available for search"?
Node hosting a shard replica crashed or left the cluster ungracefully Network partition isolates nodes so the cluster loses connectivity with shard replicas Insufficient disk space on data nodes prevents shard allocation
Is the "ShardNotFoundException: no shard available for search" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading