Lesson 0008 · Performance & Ops
How many shards should an index have? — and the failure mode that quietly wrecks clusters.
From memory: a shard is made of what, and where does per-segment metadata live? — A shard is a Lucene index built from segments, and ES keeps segment metadata in heap (0005). That single fact — a shard costs heap even when nearly empty — is the whole reason this lesson exists.
Each shard is a full Lucene index, and it carries fixed overhead regardless of how little data it holds: “Every index and every shard requires some memory and CPU resources… In most cases, a small set of large shards uses fewer resources than many small shards.” — Size your shards
Sharding buys parallelism — a search fans out across shards and runs them concurrently. But every shard added is more of the overhead above. The two ways to get it wrong:
The docs put the cost starkly: “Searching a thousand 50MB shards will be substantially more expensive than searching a single 50GB shard containing the same data.” — Size your shards
| Guideline | Value | Why |
|---|---|---|
| Shard size | 10–50 GB | 50 GB is the common ILM rollover trigger; 10 GB a sensible floor. |
| Docs per shard | < 200 million | Lucene addressing & performance headroom. |
| Shards per data node | ≤ ~1,000 | “Each non-frozen data node supports up to 1,000 shards.” |
| Master heap | ~1 GB / 3,000 indices | Cluster-state bookkeeping lives on master-eligible nodes. |
Numbers: Size your shards · Node & shard size best practices
The classic “20 shards per GB of heap” guideline was deprecated in Elasticsearch 8.3. Per-shard overhead dropped sharply in 7.x/8.x (compact metadata, off-heap structures, compressed cluster state), so quoting it now signals stale knowledge. Reason from shard size and per-node shard count instead. — Node & shard size best practices
“Too many shards can degrade search performance and make the cluster unstable. This is referred to as oversharding.” The thread-pool mechanism is the sharp edge: “Most searches hit multiple shards. Each shard runs the search on a single CPU thread… searches across a large number of shards can deplete a node's search thread pool.” — Size your shards
It usually creeps in via many small indices (per-tenant, per-day time series with low
volume) each with default primaries. Fixes: consolidate with _reindex, reduce
primaries with _shrink, or use ILM rollover so a new shard
starts only at ~50 GB — not every day regardless of size.
Estimate total data, divide by a target shard size (~40 GB is a safe mid-band), round up:
primaries ≈ ceil(total_GB / 40). 300 GB → 8 primaries. Then check it against
the per-node shard cap and your docs-per-shard headroom. Test with realistic data before committing —
the docs' one universal rule is benchmark.
From memory — effortful recall is the point. Feedback is immediate.
Compared to many small shards, a few large shards use:
Each shard runs a given search on:
The recommended shard size range is about:
Too many tiny shards primarily causes:
The old “20 shards per GB heap” rule is now:
On your live cluster. This makes the overhead visible in real numbers.
GET /_cluster/health // active_shards, active_primary_shards
GET /_cat/nodes?v&h=name,heap.percent,ram.percent,node.role
GET /_cat/shards?v&s=index // every shard, its size and node
Note your total shard count and per-node heap. On a single-node dev box you'll see replicas sit
UNASSIGNED — that's expected (a replica never shares a node with its primary).
PUT /lab_over
{ "settings": { "number_of_shards": 12, "number_of_replicas": 0 } }
PUT /lab_over/_doc/1?refresh=true
{ "title": "one tiny document" }
GET /_cat/shards/lab_over?v&h=shard,prirep,docs,store // 12 shards for 1 doc
Twelve shards, eleven of them holding zero documents — each still a Lucene index with its own heap and file-handle cost. This is over-sharding in miniature.
Compute the right count for a real dataset: for an expected 300 GB,
ceil(300 / 40) ≈ 8 primaries. Confirm the arithmetic, then DELETE /lab_over.
Bring your _cat/shards survey to your teacher and we'll sanity-check your real indices.
Size your shards (Elastic Docs, current) — the authoritative guidance, with the reasoning behind every number. Pair it with the Labs post Node & shard size best practices for the modern (post-8.3) rules.