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

Retry Elasticsearch Indices Stuck on a Failed ILM Step

Find Elasticsearch indices stuck on a failing ILM step, retry the step after a human clears the cause, then verify the lifecycle started moving again.

Categories
Infrastructure

When an index lifecycle step errors, the index stops moving through its lifecycle. Rollover, forcemerge, shrink, searchable snapshot, delete: none of them happen. The index keeps taking writes and keeps growing, retention never runs, the hot tier fills up. Nothing alerts, because every shard is still allocated so the cluster stays green and every dashboard looks fine. The usual causes are small configuration mistakes: a index.lifecycle.rollover_alias that does not point at the index, a read-only block left behind by a disk watermark, a shrink target that is not free. This blueprint reads the full ILM state, lists the indices that are failing a step with the step name plus the reason Elasticsearch recorded, then sends POST /<index>/_ilm/retry behind a dry run plus an approval gate, waits out the lifecycle poll, re-reads ILM and fails the run if a targeted index is still failing the same step.

Findings

  • A retry is not a fix. ILM re-runs the step that failed, so an unchanged cause fails again within a poll. The approval gate is therefore not a request to approve a retry, it is a request to confirm the recorded cause is cleared. The brief printed before the gate carries the per-index reason so the approver is answering the right question.
  • The ERROR step is not a steady state. For an error Elasticsearch marks auto retryable it takes the index out of ERROR for the whole poll in which it re-runs the step, clearing failed_step plus step_info while failed_step_retry_count keeps climbing. Measured on 8.15.3 with a one second poll interval: GET _ilm/explain?only_errors=true returned an empty result for an index that had already burned 244 retries on the same step. A scan built on only_errors misses a permanently stuck index for half of its cycle. This flow reads the whole explain output instead and treats a present failed_step_retry_count as the signal that survives both halves.
  • POST /<index>/_ilm/retry answers HTTP 400 with "cannot retry an action for an index that has not encountered an error" when it lands inside that re-run window. The flow logs the status per index rather than trusting it, so a raced retry can never read as a fix. The re-read is the only thing that decides the outcome.
  • The retry resets the step, then the step runs on the next ILM poll. A failure needs one more poll to land back in ERROR. That is why verify_wait exists: it has to clear two poll intervals, which on a stock cluster is 20 minutes because indices.lifecycle.poll_interval defaults to 10 minutes.
  • An index in the ERROR step with no failed step cannot be retried at all. A missing policy looks exactly like that. Those indices are listed in the report plus the Slack alert, then left alone.
  • An index that is stuck without being in ERROR is also left alone. A shrink whose target shard count is not a factor of the source parks the index on check-target-shards-count with a step_info.message rather than an error. The retry API rejects that index.
  • 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. The same task deserializes the response body into a map, so a _cat endpoint with format=json fails the task on its JSON array. Every endpoint used here returns a JSON object.

How it works

  1. detect_status (io.kestra.plugin.elasticsearch.Request) reads GET _ilm/status for the ILM operation mode.
  2. detect_explain reads GET {index_pattern}/_ilm/explain in full. detect_settings reads the hidden flag per index so system indices can be filtered out.
  3. check_reads (io.kestra.plugin.core.flow.If) fails the run when any read did not return 200.
  4. plan (io.kestra.plugin.core.output.OutputValues) keeps every managed index whose step is ERROR or which still carries failed_step_retry_count, with its phase, action, failed step, retry count, is_auto_retryable_error flag plus the step_info reason. Indices in ERROR with no failed step are held in a separate list that is reported, never retried.
  5. summary builds the per-index detail line plus the list of distinct causes. report logs the mode, the counts, the policies plus those causes.
  6. alert_detected posts a Slack findings alert whenever anything is flagged, before any remediation decision, so a plain scan or a dry run both alert. The payload is assembled as a map then serialized, so a reason containing quotes or newlines cannot break the JSON.
  7. route acts only when something is flagged, auto_remediate is true plus dry_run is false. scope_gate then refuses unless ILM is RUNNING plus the count is at or under max_error_indices, logging the refusal then failing so the alert fires.
  8. root_cause_brief prints what the approver is confirming: the failed step, the recorded reason plus what clearing it means. approval_gate (io.kestra.plugin.core.flow.Pause) then holds the run.
  9. remediate_retry (io.kestra.plugin.core.flow.Loop, concurrencyLimit: 1) sends one POST {index}/_ilm/retry per flagged index. settle waits verify_wait so the retried step has time to run plus fail.
  10. reverify_explain re-reads ILM. verify_result fails the run when any targeted index is in ERROR again or still carries a retry count. 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 lifecycle that starts moving again, so rollover, forcemerge plus delete happen on the schedule the policy already describes.
  • The actual reason per index, taken from step_info, instead of a count of broken indices.
  • The auto retry count per index, which is the number nobody looks at. A climbing count is proof the cause is still present.
  • A detector that does not lose a stuck index while Elasticsearch is re-running its failed step.
  • Precision by construction: an index a retry cannot help is reported, never touched. System indices stay out unless you opt in.
  • Proof the retry worked, from a re-read of ILM after the poll, not from a 200 on the retry call.
  • Slack on detection plus Slack on failure, both through a secret.
  • Outputs to chain on: outputs.plan.values.targets_json holds the flagged indices with their failed step plus reason, outputs.plan.values.noretry_json the ones a retry cannot help, outputs.summary.values.causes the distinct causes, outputs.verify_plan.values.still_json whatever is still failing after a pass.

Who it's for

  • Platform teams whose hot tier keeps filling up while every index template looks correct.
  • Anyone who has found an index months past its delete phase because one rollover step failed once.
  • Teams running ILM across many indices where a template change breaks the lifecycle of everything created after it.

Why orchestrate this with Kestra

Retrying a lifecycle step is cheap to call plus easy to get wrong, because a retry with the cause still present just re-enters the same failure. The value is the sequence around it: read the real reason, show it to a human, wait for a decision, wait out the poll interval, then read the system again to decide whether the run passed. A flow records all of that against one execution id, with the read-only default plus the approval gate making a careless pass hard. The run turns red on a lifecycle that is still stuck, which is what makes it safe to schedule.

Tested end to end

Verified on Kestra 2.0.5 against Elasticsearch 8.15.3 with security disabled on a single node. An ILM policy with a rollover action was attached to an index whose index.lifecycle.rollover_alias pointed at a different alias, which parks the index on check-rollover-ready in the ERROR step. A second index managed by a policy with no rollover action was left healthy, a third was pointed at a policy that does not exist, a fourth was parked on check-target-shards-count by an impossible shrink. Eleven runs covered the clean scan, detection, dry run, approved remediation with the cause cleared, approved remediation with the cause still present, a declined approval, a settle window shorter than the poll interval, the refusal when ILM is stopped, the refusal above max_error_indices plus an unreadable index pattern. Of five managed indices the flow flagged exactly one, reported the missing-policy index separately, left the healthy index plus the non-error stuck index alone. With the cause cleared the index went from ERROR to hot/complete/complete with the retry count cleared and the rollover produced the next index. With the cause still present the index was back on the same step inside the settle window and the run failed. Every number was read back from the Elasticsearch REST API, never off the Kestra log.

Prerequisites

  • A reachable Elasticsearch cluster with index lifecycle management in use. For a secured cluster, credentials allowed to read _ilm/status, _ilm/explain plus index settings, plus permission to call _ilm/retry.
  • A Slack incoming webhook for the findings alert plus the failure alert.

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 plus hidden indices too.
  • max_error_indices: the flow refuses to retry when more than this many indices are failing, because that many at once points at one shared cause.
  • verify_wait: how long to wait after the retry before re-reading. Set it to at least twice indices.lifecycle.poll_interval.
  • dry_run plus auto_remediate: the two safety gates. A retry 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 then run once with the defaults. The report names every index that is failing a step with the reason behind it.
  3. Clear those causes. The reason text usually names the setting to fix.
  4. Read your cluster's indices.lifecycle.poll_interval from GET _cluster/settings?include_defaults=true then set verify_wait to at least twice that.
  5. Run with auto_remediate true plus dry_run false, read the approval brief, then resume the Pause with approved true.
  6. 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 to one lifecycle.
  • Set max_error_indices to 1 to make the flow handle single-index mistakes on its own while refusing anything that looks cluster wide.
  • Chain a flow off this flow's FAILED state to open a ticket, since a retry that failed means the cause is still live.
  • Add a step that reads the index template behind a flagged index, so a bad rollover_alias is fixed at the source rather than per index.
  • Feed the detected list into a report of lifecycle debt per policy, using the retry count as the age signal.

Links

This blueprint was created by zkasuran.

See How

New to Kestra?

Use blueprints to kickstart your first workflows.