Skip to content

Lesson 7 of 9 · 27m

Shards, Allocation, and What Cluster Health Really Means

Interpret green, yellow, and red correctly, read allocation explanations, size shards pragmatically, and understand replica behavior during node loss.

Cluster health colors are useful but routinely misunderstood. Green does not mean fast. Yellow does not mean data loss. Red means at least one primary shard is unavailable and some data cannot currently be written or searched. The color is a shard allocation summary, not a full statement of business impact. Operators need to look one layer lower.

Shards are the unit of distribution

An index is split into primary shards, each optionally copied to replica shards. Replicas provide high availability and search capacity, not backup in the disaster-recovery sense. A corrupt or logically deleted document can be faithfully replicated.

index: orders
primary shards: 3
replicas: 1
total shard copies: 6

A node holding a primary and another holding its replica can serve reads. If both copies are lost, redundancy has failed. This is why allocation awareness across zones or hosts matters.

Yellow is often a replica placement problem

A single-node cluster with any index configured for one replica is usually yellow because there is nowhere else to place the replica. That may be acceptable in a lab and unacceptable in production. Inspect allocation rather than guessing:

curl -s 'http://localhost:9200/_cluster/allocation/explain?pretty'   -H 'content-type: application/json' -d '{
    "index": "orders",
    "shard": 0,
    "primary": false
  }'

The explanation may mention node count, awareness attributes, disk watermarks, allocation filtering, or shard state.

Red requires calm triage

Start with cluster health and shard state:

curl -s 'http://localhost:9200/_cluster/health?pretty'
curl -s 'http://localhost:9200/_cat/shards?v&h=index,shard,prirep,state,node,unassigned.reason'   | sort | head -40

Then inspect node logs and allocation explanations. Common causes include disk watermarks, corrupted shard data, nodes missing after restart, allocation rules, and version incompatibility after partial upgrades. Do not randomly delete data because a shard is red; you may convert a recoverable availability incident into permanent loss.

Shard sizing is boring on purpose

Oversharing is the classic beginner mistake. Thousands of tiny shards consume heap and cluster state even when each holds little data. Very large shards complicate recovery, relocation, and parallelism. A common practical target is tens of gigabytes per shard, often roughly 10-50 GB depending on workload and hardware, but measure rather than worship a number.

Time-series indexes should roll over based on size and age, not merely because a calendar day changed:

{
  "actions": {
    "rollover": {
      "max_primary_shard_size": "30gb",
      "max_age": "7d"
    }
  }
}

Replicas trade write cost for resilience and read capacity

Increasing replicas can improve query throughput and survive node loss, but every write must be indexed on every copy. During heavy ingestion, replicas increase load. Some teams reduce replicas during controlled bulk backfills and restore them afterward, but that is an operational trade with a risk window, not a universal trick.

Field notes

  • GET _cat/health is not enough for root cause; _cat/shards, allocation explain, and node logs are the real starting points.
  • Cluster state grows with indexes, fields, and shards. Small objects still create coordination overhead.
  • A replica is not a snapshot. Backup and availability solve different problems.
  • Changing shard count generally requires reindexing or rollover into a new index; it is not an in-place knob for existing primaries.

Was this lesson helpful?

Sign in to rate