Skip to content

Elasticsearch shard sizing strategy

Learn how to choose the right shard size and shard count for an Elasticsearch index. This guide shows how to spot too many or too few shards, and how to fix an existing index without reindexing it.

This guide helps you decide how big each shard should be in an Elasticsearch cluster, and how many shards an index needs. It is for operators planning a new index or fixing a cluster that has hit its shard limit. A shard is one piece of an index, and Elasticsearch spreads those pieces across the servers (nodes) in your cluster.

Getting the size wrong hurts in two ways. Many tiny shards waste memory, because each one uses part of the Java heap (the memory Elasticsearch reserves for itself). A few huge shards make recovery slow after a node restarts or fails.

The short answer is to aim for shards between 10 GB and 50 GB, and about 30 GB for logs. Below, you will find a simple formula for the shard count. You will also see how to repair an existing index with the shrink API (fewer shards) or the split API (more shards).

How to verify

Check the current shard landscape before changing anything:

curl -sk -u elastic:"$PW" 'https://es:9200/_cat/shards?v&s=index&h=index,shard,prirep,state,store,docs,node'
curl -sk -u elastic:"$PW" 'https://es:9200/_cat/allocation?v'
curl -sk -u elastic:"$PW" 'https://es:9200/_cluster/stats?pretty' | jq '.indices.shards'
curl -sk -u elastic:"$PW" 'https://es:9200/_cluster/settings?include_defaults=true&filter_path=**.cluster.max_shards_per_node*'

Pay attention to: total shard count per node (cluster.max_shards_per_node default 1000), average shard size, ratio of empty/small shards to full ones.

What’s happening

Each shard is a Lucene index — a full searchable unit with its own segments, file handles, JVM heap overhead, and refresh cycle. Two opposing failure modes:

  • Under-sharding — fewer, larger shards. Queries can be slow on giant shards (recovery time grows linearly with size), and you can’t parallelize search across nodes if a shard is bigger than the largest node can hold.
  • Over-sharding — many tiny shards. Each shard costs 50-100 MB of heap as a baseline, file descriptors compound, and queries fan out to too many shards, paying per-shard overhead. Recovery from snapshot takes hours when you have 100k+ shards.

The Elastic-recommended target is shards between 10 GB and 50 GB for search workloads, 20-40 GB for log workloads. Below 1 GB is wasteful; above 65 GB starts hurting recovery. Aim for primary shard size of 30 GB at rollover for logs.

Total shard count per node should stay below 600 in practice (the default 1000 limit is a hard cap, not a healthy operating point). Each shard adds heap pressure independent of data size.

The decision

For a new index pattern, compute shard count from expected total size:

shards = ceil(total_index_size / target_shard_size)

For 600 GB of data with 30 GB target: 20 primary shards, 1 replica = 40 shards total. Distribute across nodes such that no node holds more than ~20% of primaries (rebalance friendly).

For time-series logs, use rollover with max_primary_shard_size: 30gb, max_age: 7d, and a fixed shard count of 1 (let rollover create more indices, not more shards per index).

Rules of thumb:

  1. Shards × nodes ≥ 2 for resilience. A single shard on a 3-node cluster wastes 2 nodes worth of capacity.
  2. Shards ≤ data nodes × 2 for primary distribution. More shards than that and rebalancing thrashes.
  3. Replica count = 1 minimum for any production data you care about. Going to 2 doubles write cost but survives one node failure during recovery.

The procedure

1. Diagnose over-sharding — total shards in cluster divided by data nodes:

TOTAL=$(curl -sk -u elastic:"$PW" 'https://es:9200/_cluster/stats?filter_path=indices.shards.total' | jq '.indices.shards.total')
NODES=$(curl -sk -u elastic:"$PW" 'https://es:9200/_cat/nodes?h=name,node.role' | grep -c d)
echo "Average shards per data node: $((TOTAL / NODES))"

If average is over 600, over-sharded. Continue to step 2 or 3.

2. Fix over-sharded indices via _shrink (reduces primary shard count of an existing index by a factor that divides the original count evenly):

# Step A: prepare source — make read-only, move all shards to one node
curl -sk -u elastic:"$PW" -X PUT 'https://es:9200/logs-old-index/_settings' \
  -H 'Content-Type: application/json' \
  -d '{
    "settings": {
      "index.routing.allocation.require._name": "data-node-1",
      "index.blocks.write": true
    }
  }'

# Step B: wait for relocation to finish
curl -sk -u elastic:"$PW" 'https://es:9200/_cluster/health?wait_for_no_relocating_shards=true&timeout=30s'

# Step C: shrink from 20 shards to 4
curl -sk -u elastic:"$PW" -X POST 'https://es:9200/logs-old-index/_shrink/logs-old-index-shrunk' \
  -H 'Content-Type: application/json' \
  -d '{
    "settings": {
      "index.number_of_shards": 4,
      "index.number_of_replicas": 1,
      "index.routing.allocation.require._name": null,
      "index.blocks.write": null
    }
  }'

Constraint: target shard count must divide source count evenly (20 → 10, 5, 4, 2, or 1).

3. Fix under-sharded indices via _split (increases primary shard count):

# Step A: make source read-only
curl -sk -u elastic:"$PW" -X PUT 'https://es:9200/products/_settings' \
  -H 'Content-Type: application/json' \
  -d '{"settings": {"index.blocks.write": true}}'

# Step B: split from 1 shard to 4
curl -sk -u elastic:"$PW" -X POST 'https://es:9200/products/_split/products-split' \
  -H 'Content-Type: application/json' \
  -d '{
    "settings": {
      "index.number_of_shards": 4,
      "index.number_of_replicas": 1,
      "index.blocks.write": null
    }
  }'

Constraint: target must be a multiple of source (1 → 2, 4, 8, 16; or 2 → 4, 8, 16, 32).

4. Swap the alias to point at the new index:

curl -sk -u elastic:"$PW" -X POST 'https://es:9200/_aliases' \
  -H 'Content-Type: application/json' \
  -d '{
    "actions": [
      {"add":    {"index": "logs-old-index-shrunk", "alias": "logs-current"}},
      {"remove": {"index": "logs-old-index",        "alias": "logs-current"}}
    ]
  }'

5. Delete the original after verifying queries against the new index.

Common pitfalls

  • Shard count of 5 by default (pre-7.x). New indices default to 1 in modern versions, but legacy code/Helm charts often request 5 — adjust.
  • Shrinking a single-shard index does nothing. The destination must have fewer shards than the source.
  • Splitting requires more disk temporarily — the new index is created alongside, not in place. Budget 2x the source size during split.
  • Cluster-level max_shards_per_node is a hard limit, not a soft warning. New index creation fails when breached. Raise via cluster.max_shards_per_node only as a stopgap; the real fix is fewer shards.
  • Replica auto-expand (auto_expand_replicas) on small indices creates one replica per node — fine for system indices, terrible if accidentally applied to large data.

In the engagements we run, shard sizing problems are almost always over-sharding caught late — every new daily log index gets 5 shards and the cluster has 80k tiny shards by year’s end. The fix is the ILM rollover pattern with 1 primary shard per rollover and shrink retroactively for warm-phase indices. See /en/services/managed-operations/ for how we run search infrastructure with shard counts that stay healthy.