Cluster Administration and Operations
10 min read
So, you have successfully deployed Elasticsearch, created some indices, and pushed millions of documents into it. The search bar is fast, the users are happy, and you feel like a database wizard. But then, it happens. A disk fails. Traffic spikes. The cluster indicator turns angry red at 3:00 AM, and your phone starts buzzing with PagerDuty alerts.
Building a cluster is development; keeping it alive and performant is operations. In the industry, cluster administration is the difference between a minor hiccup and a resume-generating outage.
In this guide, we are going deep into the operations side of Elasticsearch. We will cover cluster health, node roles, backups, and disk management. We will focus strictly on what you actually need to know to keep the lights on in a production environment.
1. Checking Cluster Health and Status (Red, Yellow, Green)
Definition: Cluster health is a status indicator that reports the allocation state of primary and replica shards across the nodes in an Elasticsearch cluster.
The Problem: An Elasticsearch cluster distributes data (shards) across many machines (nodes). If a machine unplugs, crashes, or runs out of memory, pieces of your data go missing. If you have to manually check every node to see if data is missing, you would spend all day running diagnostics. We need a single, immediate indicator of data integrity.
How it Solves the Problem: Elasticsearch continuously monitors where every shard is located and gives you a simple, traffic-light color code representing the overall data availability.
The Real-Life Scenario
Imagine you are running a hospital triage system.
- Green (Healthy): Everyone is fine. All doctors are present, and all backup doctors are on standby.
- Yellow (Warning): A backup doctor called in sick. The hospital is still functioning perfectly, and patients are being treated, but if the main doctor gets sick right now, you are in trouble.
- Red (Critical): The main doctor is missing, and patients (data) cannot be treated (read/written).
The Status Colors Explained
- 🟢 Green: All primary and replica shards are allocated. Your cluster is 100% operational and resilient.
- 🟡 Yellow: All primary shards are allocated, but one or more replica shards are missing.
- Industry reality: Your cluster functions perfectly. Searches work, writes work. But if the node holding the primary shard crashes right now, you will lose data. Single-node clusters are always Yellow if you have replicas configured, because Elasticsearch refuses to put a replica on the same machine as the primary (that defeats the purpose of a backup).
- 🔴 Red: One or more primary shards are missing.
- Industry reality: Panic time. Some of your data is entirely unavailable. Searches will return partial results, and writes to the affected indices will fail.
Hands-on Practice
To check your cluster health, run this in Kibana Dev Tools (or via curl):
GET /_cluster/healthResponse snippet:
{
"cluster_name": "production-cluster",
"status": "yellow",
"timed_out": false,
"number_of_nodes": 3,
"number_of_data_nodes": 3,
"active_primary_shards": 15,
"active_shards": 15,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 5,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 75.0
}Interesting Fact: Most engineers spend 90% of their debugging time staring at the unassigned_shards metric. If you want to know why a shard is unassigned (and thus why your cluster is Yellow or Red), use the cluster allocation explain API:
GET /_cluster/allocation/explainThis command is the holy grail of Elasticsearch debugging. It will literally tell you in plain English: "I cannot assign this replica because the disk is over 90% full."
2. Node Roles and Dedicated Hardware Strategies
Definition: Node roles are configuration settings applied to an Elasticsearch instance that dictate which specific tasks (e.g., storing data, routing traffic, managing cluster state) the node is allowed to perform.
The Problem: By default, every node you spin up tries to do everything. It stores data, it routes user searches, it manages the cluster, and it runs machine learning jobs. If a heavy search query maxes out a node's CPU, that node might fail to perform its cluster management duties, causing the entire cluster to collapse.
How it Solves the Problem: By separating concerns, we assign specific jobs to specific machines. This isolates failures and allows us to purchase specialized hardware (e.g., cheap CPUs with massive hard drives for data; expensive CPUs with small drives for routing).
The Real-Life Scenario
Imagine a restaurant. If the same person is taking orders, cooking the food, managing the payroll, and taking out the trash, they will inevitably drop a plate or burn a steak.
Instead, you hire dedicated staff:
- The Manager (Master Node): Doesn't cook, doesn't serve. Just makes sure the restaurant is running and staff are present.
- The Chef (Data Node): Stays in the back, works hard, handles the heavy lifting (the actual data).
- The Waiter (Coordinating Node): Takes the order from the customer, routes it to the right chef, gathers the plates, and hands the final meal to the customer.
Core Industry Roles
Since Elasticsearch 8.x, roles are defined in the elasticsearch.yml file using an array.
1. Master-eligible Node (master)
Manages cluster state, creates/deletes indices, and tracks which nodes are in the cluster.
- Hardware: Low CPU, Low RAM, Low Disk. Highly stable network.
- Rule of thumb: Always have exactly 3 dedicated master nodes in production. This prevents "split-brain" scenarios (where two nodes both think they are the boss).
2. Data Node (data)
Holds the actual shards and performs CRUD, search, and aggregations.
- Hardware: High CPU, High RAM, Massive fast SSDs.
- Industry Standard: We often split data nodes into a Hot-Warm-Cold architecture.
data_hot: Fast SSDs for today's logs (frequently queried).data_warm: Cheaper HDDs for last month's logs (infrequently queried).data_cold: Very cheap, slow storage for compliance archives.
3. Coordinating Node (Empty roles array)
If you strip all roles from a node (node.roles: []), it becomes a smart load balancer. It receives search requests, scatters them to the data nodes, gathers the results, and sorts them.
- Hardware: High CPU, High RAM, virtually zero disk space.
Hands-on Practice
In your elasticsearch.yml, you define roles like this:
# A dedicated Master Node
node.roles: [ master ]
# A dedicated Hot Data Node
node.roles: [ data_hot ]
# A Coordinating Node (acts as a router/load balancer)
node.roles: [ ]3. Backups: Configuring Snapshots and Restores
Definition: Snapshots are incremental, point-in-time backups of an Elasticsearch cluster's indices and state, stored in an external remote repository.
The Problem: Disks die, data centers catch fire, and sometimes a junior developer accidentally runs DELETE /* in production instead of their local machine. Replicas protect against hardware failure, but they do not protect against human error (if you delete a document, the replica deletes it instantly too).
How it Solves the Problem: Snapshots allow you to push a compressed copy of your data to external storage (like AWS S3 or Google Cloud Storage). Because they are incremental, only the data that changed since the last snapshot is uploaded, saving massive amounts of time and bandwidth.
The Real-Life Scenario
Think of snapshots like saving your progress in a video game. If you make a terrible decision and lose all your gold (run a bad update query), you can't just undo it. But you can reload the save file from 10 minutes ago. And since the game only saves what changed since the last save point (incremental), saving is extremely fast.
Hands-on Practice
In the industry, 99% of snapshots go to cloud object storage. To do this, we use the Snapshot Lifecycle Management (SLM) APIs.
Step 1: Register a Repository
First, tell Elasticsearch where to put the backups. (Note: You usually need to install a plugin like repository-s3 on all nodes first).
PUT /_snapshot/my_s3_backup
{
"type": "s3",
"settings": {
"bucket": "my-elasticsearch-backups-bucket",
"region": "us-east-1"
}
}Step 2: Take a Snapshot manually
Let's back up everything right now.
PUT /_snapshot/my_s3_backup/snapshot_monday?wait_for_completion=trueStep 3: Oh no, we deleted the production index! Restore it!
When restoring, you can pick specific indices.
POST /_snapshot/my_s3_backup/snapshot_monday/_restore
{
"indices": "production-users",
"ignore_unavailable": true,
"include_global_state": false
}Industry Practice: Nobody does this manually every day. We use Elasticsearch's SLM (Snapshot Lifecycle Management) to automatically take a snapshot every night at 2 AM and automatically delete snapshots older than 30 days.
4. Managing Disk Watermarks and Shard Rebalancing
Definition: Disk watermarks are predefined disk usage thresholds (low, high, and flood-stage) that trigger Elasticsearch to automatically move data or block writes to prevent a node from running out of storage. Shard rebalancing is the automated process of moving shards evenly across nodes.
The Problem: If a database fills a server's hard drive to 100%, the operating system crashes, data corrupts, and the node dies. As you continuously ingest data, you need a way to ensure no single node reaches 100% capacity, especially when some nodes might hold larger shards than others.
How it Solves the Problem: Elasticsearch acts defensively. It constantly monitors the disk usage of every node. As a disk fills up, Elasticsearch hits predefined "watermarks" (like alarms) and takes automated actions to save itself—first by moving data away, and ultimately by locking the disk to read-only mode.
The Real-Life Scenario
Imagine packing suitcases for a flight.
- Low Watermark (85%): Your first suitcase is getting heavy. You decide not to put any new items in this one, and start putting new items in the second suitcase.
- High Watermark (90%): The first suitcase is dangerously full. You actively start taking heavy shoes out of it and moving them to the second suitcase.
- Flood-Stage Watermark (95%): The zipper is about to break. You violently lock the suitcase, slap a padlock on it, and scream at anyone who tries to add another pair of socks.
The Thresholds Explained
Elasticsearch uses three default watermarks:
- Low Watermark (85% disk used): ES will not allocate any newly created primary or replica shards to this node.
- High Watermark (90% disk used): ES actively starts moving existing shards off this node to other nodes that have more space (Shard Rebalancing).
- Flood-Stage Watermark (95% disk used): Self-preservation mode. ES blocks all write requests to any index that has a shard on this node. Your application will start throwing errors (
cluster_block_exception), but your server won't crash.
Funny Exaggeration: A node hitting flood-stage is like a squirrel hoarding nuts until its tree literally snaps in half. Elasticsearch steps in and revokes the squirrel's hoarding license.
Hands-on Practice
If you have massive disks (e.g., 10 Terabytes), 85% leaves 1.5 TB of free space, which is a massive waste of expensive hardware. In the industry, we often change these settings from percentages to absolute byte values.
You can dynamically update these watermarks without restarting the cluster:
PUT /_cluster/settings
{
"persistent": {
"cluster.routing.allocation.disk.watermark.low": "100gb",
"cluster.routing.allocation.disk.watermark.high": "50gb",
"cluster.routing.allocation.disk.watermark.flood_stage": "10gb"
}
}In this configuration: Elasticsearch will only stop putting new data on a node when it has less than 100GB of free space left, rather than using percentages.
Fixing a Flood-Stage Block:
If you ever hit 95% and your indices get locked to read-only, freeing up disk space will not automatically unlock them. You have to manually tell Elasticsearch to lift the quarantine once space is cleared:
PUT /_all/_settings
{
"index.blocks.read_only_allow_delete": null
}Wrapping Up
Cluster administration isn't just about keeping the lights green; it's about anticipating failures. By understanding health statuses, giving your nodes dedicated jobs, automating your backups, and respecting disk limits, you transform your Elasticsearch cluster from a fragile house of cards into a robust, self-healing data engine.
References and Extra Reading
Challenge
As an Elasticsearch administrator, you are responsible for disaster recovery. Your task is to create a robust, automated backup policy using Snapshot Lifecycle Management (SLM).
Write the complete API call to create a new SLM policy with the following specifications:
- Policy Name: The policy must be named
critical_data_backup. - Schedule: Snapshots must be taken every six hours, starting at midnight UTC.
- Repository: Use the pre-configured S3 repository named
disaster-recovery-s3. - Index Targeting:
- Include all indices matching the patterns
transactions-*anduser_profiles. - Explicitly exclude any indices matching the pattern
transactions-log-archive-*.
- Include all indices matching the patterns
- Configuration: The snapshot process must not fail if an index is unavailable during the operation.
- Retention: Snapshots must be retained for 180 days, after which they should be automatically deleted.
Expected result
The solution must be a single PUT API request targeting the /_slm/policy/critical_data_backup endpoint. The body of the request must be a JSON object containing the SLM policy definition.
Key fields in the JSON body must include:
schedule: A cron expression representing a schedule of every 6 hours (e.g.,0 0 */6 * * ?).repository: The stringdisaster-recovery-s3.retention: An object specifying anexpire_aftervalue of180d.config: An object containing:indices: An array of strings that correctly specifies the patterns for both inclusion (transactions-*,user_profiles) and exclusion (-transactions-log-archive-*).ignore_unavailable: A boolean set totrue.