Schedule icon
Request icon
If icon
Fail icon
OutputValues icon
Log icon
SlackIncomingWebhook icon
Pause icon
Loop icon

Fix Elasticsearch Indices Stuck Yellow on Unplaceable Replicas

Detect Elasticsearch indices with more replicas than data nodes can place, lower them to the placeable floor, then verify no replica shard stays unassigned.

Categories
Infrastructure

Elasticsearch never puts a replica on the node that already holds its primary. So an index with number_of_replicas above data_nodes - 1 has replicas that can never be allocated. The cluster goes YELLOW and stays YELLOW for as long as the index exists. Nothing in Elasticsearch fixes this on its own, nothing retries, no amount of waiting helps. The damage is not the missing copy, it is the signal: a permanently yellow cluster masks every real health alert. Any gate that waits for green blocks forever. This blueprint finds those indices, computes the floor the topology can actually place, lowers the replica count to it behind a dry run and a human approval, then re-reads cluster health and the index settings and fails the run if a targeted index still has unassigned shards.

Findings

  • Lowering a replica count does reduce redundancy on paper. Here it does not, because the configured replicas were never placeable on this topology, so they bought no redundancy at all. They only hid the health signal. The report log explains the floor.
  • A node out for a restart shrinks data_nodes, which shrinks the floor, which would make a correctly configured index look over-provisioned. That is why min_data_nodes exists: the flow refuses to act unless the cluster reports at least that many data nodes.
  • io.kestra.plugin.elasticsearch.Request reports task success on any HTTP status, so a 4xx is silent. Every read here is gated on outputs.<id>.status and each write logs its status. The final verdict comes from a re-read of the cluster, never from task state.
  • The same task deserializes the response body into a map, so a _cat endpoint with format=json fails the task on its JSON array. The data node roster is read from _nodes/data:true with a filter_path instead.

How it works

  1. detect_health (io.kestra.plugin.elasticsearch.Request) reads GET _cluster/health for the cluster status, the unassigned shard count and number_of_data_nodes.
  2. detect_nodes reads GET _nodes/data:true with a filter_path for the named data nodes, so the floor is backed by a roster and not by one counter.
  3. detect_indices reads GET _cluster/health/{index_pattern}?level=indices, which gives each index its number_of_replicas beside its unassigned_shards. detect_settings reads the configured replica count plus the hidden flag.
  4. check_reads (io.kestra.plugin.core.flow.If) fails the run when any read did not return 200.
  5. plan (io.kestra.plugin.core.output.OutputValues) computes the floor as data_nodes - 1 with zero as the minimum, then keeps the indices whose replica count is above the floor while replica shards are actually unassigned. Dot-prefixed and hidden indices are dropped unless include_system_indices is true.
  6. report logs the floor, the roster, the flagged indices and the mode. alert_detected posts a Slack findings alert whenever something is flagged, before and apart from the remediation gate, so a plain scan or a dry run both alert.
  7. route acts only when something is flagged, auto_remediate is true and dry_run is false. nodes_gate then refuses unless at least min_data_nodes data nodes are present, logging the refusal and failing so the alert fires.
  8. approval_gate (io.kestra.plugin.core.flow.Pause) holds the run until a human resumes it with approved set true. remediate_replicas (io.kestra.plugin.core.flow.Loop, concurrencyLimit: 1) then sends one PUT {index}/_settings with {"index": {"number_of_replicas": floor}} per flagged index.
  9. reverify_health and reverify_settings re-read the cluster. verify_result fails the run when any flagged index still carries unassigned shards or still sits above the floor, which is what catches an index held back by an allocation filter rather than by its replica count.
  10. The errors block posts a Slack alert on any failure. A disabled Schedule trigger runs the scan every morning in report-only mode.

What you get

  • A cluster that can reach green, so health alerts and green gates mean something again.
  • The floor computed from the live topology instead of guessed, with the named data nodes it came from in the log.
  • A refusal to act while the cluster is short of data nodes, so a rolling restart is never mistaken for a misconfigured index.
  • Precision by construction: an index already at or under the floor is never touched. System indices stay out unless you opt in.
  • Proof the fix landed, from a re-read of health plus settings, not from a hopeful 200.
  • Slack on detection and Slack on failure, both through a secret.

Who it's for

  • Platform and SRE teams whose Elasticsearch cluster has been yellow for months with nobody sure why.
  • Anyone running a single data node for development or a small production cluster where the default number_of_replicas: 1 from a template can never be placed.
  • Teams with a deploy or ingest gate that waits for green and quietly never fires.

Why orchestrate this with Kestra

Lowering a replica count is a change to durability settings, so it needs a record of what the cluster looked like, what the floor was, who approved it and whether it worked. A flow gives all of that against one execution id. The read-only default, the min_data_nodes guard and the Pause stop a careless change during a restart. The re-read is what turns the run green or red rather than the write returning 200.

Tested end to end

Verified on Kestra 2.0.5 against Elasticsearch 8.15.3 with security disabled, on a single data node. One index was created with number_of_replicas: 1 so its replica shard could never be placed, which held the cluster yellow with one unassigned shard. A second index already at zero replicas was left in place to prove precision. The clean, detect, dry-run, approved-remediation, declined-approval and refused-by-min-data-nodes paths were all run. The cluster went from yellow with one unassigned shard to green with zero, the flagged index moved from one replica to zero, the already-correct index stayed untouched. Every number was confirmed with a direct call to the Elasticsearch REST API rather than read off the Kestra log. A deliberately unfixable index, pinned by an allocation filter to a node name that does not exist, made the re-verify step fail the run as designed.

Prerequisites

  • A reachable Elasticsearch cluster. For a secured cluster, credentials allowed to read cluster health, node info and index settings and to update index settings.
  • A Slack incoming webhook for the findings and failure alerts.

Secrets

  • ELASTICSEARCH_USERNAME: username for basic auth, when the cluster has security enabled.
  • ELASTICSEARCH_PASSWORD: password for basic auth, when the cluster has security enabled.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for alerts.

Inputs

  • elasticsearch_url: base URL of the cluster.
  • index_pattern: index or pattern to inspect, * by default.
  • include_system_indices: set true to inspect dot-prefixed and hidden indices too.
  • min_data_nodes: the flow refuses to act below this many data nodes. Set it to your normal data node count.
  • dry_run and auto_remediate: the two safety gates. A change runs only when auto_remediate is true and dry_run is false, then only after the Pause is resumed with approved true.

Quick start

  1. Add the Slack webhook secret plus the Elasticsearch credentials if your cluster is secured.
  2. Set elasticsearch_url and run once with the defaults to see the floor and which indices sit above it.
  3. Set min_data_nodes to the number of data nodes the cluster has when everything is up.
  4. Run with auto_remediate true and dry_run false, then resume the Pause with approved true to lower the flagged indices.
  5. Set disabled: false on the daily trigger to scan every morning in report-only mode.

How to extend

  • Point index_pattern at one family such as logs-* to scope a pass.
  • Raise min_data_nodes above your node count to make every remediation pass refuse and fail while the Slack findings alert keeps firing.
  • Fix the source as well as the symptom by chaining a flow that lowers number_of_replicas in the index template the flagged indices came from.
  • Chain a flow off this flow's FAILED state to open a ticket when an index stays unassigned after the pass, since that is an allocation problem the replica count cannot fix.

Links

This blueprint was created by zkasuran.

See How

New to Kestra?

Use blueprints to kickstart your first workflows.