Elasticsearch & Lucene (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Shard Sizing and Allocation: Why 20GB-50GB per shard is the golden rule and diagnosing "Too many shards".
senior LevelelasticsearchAdvanced Internals
In Simple Words: Every Elasticsearch shard is a full Apache Lucene index requiring its own file descriptors, term indices, and memory buffers:
- The Golden Rule: Aim for primary shard sizes between 20 GB and 50 GB for logs/time-series data, and 10 GB to 30 GB for search catalogs.
- Too Many Shards Anti-Pattern: Having 5,000 100MB shards wastes massive heap memory on segment headers and overloads the master node cluster state.
- Rule of Thumb: Keep total shards under 20 shards per GB of allocated JVM heap memory.