Skip to content
SeeItFlow
Interactive guide · 12 chapters · ~22 min read

Elasticsearch in Production

A badly mapped field or an oversharded index behaves fine at demo scale and falls over under real query volume — mapping explosion and shard count are two of the most common ways an Elasticsearch cluster degrades silently before it fails loudly. This section covers index design, sizing, and the operational signals that catch both early.

Mangesh MandlikLast updated:
01 · Index design

Index Design

How you split data into indices affects everything downstream — query performance, retention, and how easily you can reindex later.

Time-based indices

For log/event data, creating one index per day/week (e.g. logs-2026.08.08) makes it trivial to drop old data cheaply — deleting a whole index is far faster than deleting matching documents. In modern Elasticsearch, prefer a data stream (for append-only time-series data) managed by an index lifecycle management (ILM) policy: the policy rolls over the backing index by age or size and handles retention automatically, instead of cron jobs that create and delete dated indices by hand.

Index aliases

An alias points at one or more underlying indices, letting you reindex into a new index and atomically switch traffic over without any application changes.

02 · Mapping design

Mapping Design

Mapping decisions made on day one are expensive to undo — changing a field's type requires reindexing the whole index.

Explicit mappings

Define mappings explicitly rather than relying on dynamic mapping in production — it prevents type-guessing surprises and keeps mapping growth (the 'mapping explosion' problem) under control.

Multi-fields

Map a field as both text and keyword (e.g. name and name.keyword) when you need both full-text search and exact matching/sorting/aggregation on the same underlying value.

03 · Shard sizing

Shard Sizing

Shard count is the single most consequential capacity decision in Elasticsearch — and one of the hardest to change after the fact.

Target shard size

Elastic's shard-sizing guidance is to aim for roughly 10GB-50GB per shard (and under about 200 million documents) — a guideline, not a hard limit. Much smaller wastes per-shard overhead; much larger hurts recovery time and search latency. With ILM, the rollover action's max_primary_shard_size can enforce the upper bound for you.

Oversharding

Too many small shards multiply cluster-state overhead and file handles per node — a common cause of slow cluster operations and degraded performance even with light data volume.

04 · Replica strategy

Replica Strategy

Replicas trade extra storage and indexing cost for both availability and read throughput — the right number depends on your read/write ratio and failure tolerance.

Availability replicas

At least 1 replica per shard is standard so a single node failure never causes data loss or a search gap — replicas are promoted automatically.

Read-scaling replicas

Because search requests can be served by any copy of a shard (primary or replica), adding replicas beyond the minimum for HA can directly increase search throughput for read-heavy workloads.

06 · Bulk indexing

Bulk Indexing

Individual index requests don't scale under high write volume — the Bulk API amortizes per-request overhead across many documents.

Batch size tuning

Larger batches amortize overhead further but increase memory pressure per request and delay when documents in that batch become searchable. Typical production batch sizes range from a few hundred to a few thousand documents, tuned empirically.

Parallel bulk requests

Multiple concurrent bulk requests (rather than one giant serial stream) generally achieve higher aggregate throughput, up to the point where the cluster's write queues start rejecting requests.

07 · Query performance

Query Performance

Most slow-query problems trace back to a small set of well-known causes: unbounded result windows, expensive aggregations, or wildcard-heavy queries.

Filter vs query context

Clauses in filter context (no scoring needed) are cacheable and typically faster than the same clause in query context — use filter for anything that doesn't need relevance scoring, like date ranges or status flags.

Deep pagination

from/size pagination gets progressively more expensive the deeper you page, because every shard must compute and sort from + size results. Use search_after for deep pagination instead.

08 · Scaling

Cluster Scaling

Elasticsearch scales by adding nodes — but scaling search and scaling indexing often call for different node roles.

Node roles

Production clusters typically separate dedicated master nodes (cluster coordination, no data), data nodes (store shards, serve search/index), and sometimes coordinating-only nodes (fan-out/merge, no data) — isolating responsibilities so a heavy query load can't destabilize cluster coordination.

Hot-warm-cold architecture

For time-series/log data, newer indices live on fast (hot) nodes for active writes, older indices move to cheaper (warm/cold) nodes for read-mostly access — balancing cost against performance as data ages. Elasticsearch implements this with data tiers (hot, warm, cold, frozen): nodes are assigned tier roles, and an ILM policy moves indices between tiers as they age.

09 · Rebalancing

Rebalancing

When nodes join, leave, or fail, Elasticsearch automatically relocates shards to keep the cluster balanced — a process that itself consumes resources.

Shard allocation awareness

Configuring rack/zone awareness prevents all replicas of a shard from landing in the same failure domain, so a single rack or availability zone outage can't take out both a primary and its replica.

10 · Monitoring

Monitoring

Cluster health status is a useful first signal, but the metrics that actually predict incidents go deeper.

Cluster health: green/yellow/red

Green = all primaries and replicas allocated. Yellow = all primaries allocated but some replicas aren't (often just a node restart in progress). Red = at least one primary shard is unallocated — data for that shard is unavailable.

Key metrics

JVM heap usage and GC pause time, indexing/search latency percentiles (not just averages), thread pool rejections, and pending tasks are the highest-signal indicators of cluster stress.

11 · Common issues

Common Production Issues

A handful of failure modes account for the vast majority of real-world Elasticsearch incidents.

Field/mapping explosion

Dynamic mapping on unpredictable JSON creates thousands of fields, bloating cluster state and slowing every operation.

Oversized shards

Shards that grow far past the recommended range slow down recovery, relocation, and even individual query latency.

Circuit breaker trips

Elasticsearch trips a circuit breaker and rejects requests when an operation (often a huge aggregation) would exceed configured memory limits — protecting the node from an out-of-memory crash at the cost of that request failing.

12 · Debugging

Debugging

Elasticsearch ships with strong introspection APIs — _cluster/health, _cat APIs, and the Profile API are the first stops for almost every production question.

_cat APIs

_cat/shards, _cat/indices, _cat/nodes give fast, human-readable snapshots of cluster and shard state — usually the fastest way to spot an unbalanced or unhealthy cluster.

Profile API

"profile": true on a search request breaks down exactly which query clauses and which shards consumed the most time — invaluable for diagnosing a single slow query rather than guessing.

Key takeaways
  1. 01Use time-based indices with aliases so retention and reindexing don't require application changes.
  2. 02Define mappings explicitly; disable dynamic mapping for unpredictable payloads to avoid mapping explosion.
  3. 03Size shards in the 10-50GB range and plan primary shard count for future growth, since it is fixed at index creation (changing it means reindexing, or split/shrink).
  4. 04Tune refresh_interval and batch size for bulk loads; always check per-item bulk failures, not just the top-level status.
  5. 05Separate master, data and coordinating node roles at scale, and run three or more master-eligible nodes (typically an odd number).
  6. 06Watch JVM GC pauses, latency percentiles, and thread pool rejections as the earliest signals of cluster stress.