Skip to content

SRCH-5887: Added Elasticsearch ILM polices#1837

Draft
igoristic wants to merge 3 commits into
mainfrom
searchelastic_ilm
Draft

SRCH-5887: Added Elasticsearch ILM polices#1837
igoristic wants to merge 3 commits into
mainfrom
searchelastic_ilm

Conversation

@igoristic
Copy link
Copy Markdown
Contributor

@igoristic igoristic commented Jun 17, 2025

This PR adds support for managing Elasticsearch index retention using https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html. It ensures that an ILM policy is created or updated, applied to a matching index template, and attached to both new and existing indices.

More details here: https://docs.google.com/document/d/1nhWg50eILV1_tglNJDl-gUk-SBy6D7Gr3raimCygnC4/edit?tab=t.0

Key enhancements:

  • Defines a hot+delete ILM policy with configurable retention age.
  • Applies the policy on index creation.
  • Updates existing indices to attach the ILM policy if not already present.
  • Waits for cluster health (yellow or better) after index creation.

ILM Policy Details

  • Hot Phase: Immediate (min_age: 0ms), sets index priority.
  • Delete Phase: Triggers at SEARCHELASTIC_INDEX_RETENTION_MIN_AGE, deletes the index.

How to Test

You can test ILM in a staging or dev environment using a short retention window to verify it’s working as expected.

  1. Set a small retention age in your environment (e.g. 1 hour):

    export SEARCHELASTIC_INDEX_RETENTION_MIN_AGE="1h"
  2. Create the index by running the Rails method:

    ES.create_index
  3. Confirm ILM policy is attached:

    curl -X GET localhost:9200/spider-searchgov/_ilm/explain?pretty
  4. After 1 hour, confirm that the index is automatically deleted.


Note:

  • For existing static indices, the script will attach the ILM policy if missing.
  • Consider using aliases and reindexing for full ILM migration (see documentation added in this PR).
  • Always validate in staging before rolling out to production.

Functionality Checks

  • You have merged the latest changes from the target branch (usually main) into your branch.

  • Your primary commit message is of the format SRCH-#### <description> matching the associated Jira ticket.

  • PR title is either of the format SRCH-#### <description> matching the associated Jira ticket (i.e. "SRCH-123 implement feature X"), or Release - SRCH-####, SRCH-####, SRCH-#### matching the Jira ticket numbers in the release.

  • Automated checks pass. If Code Climate checks do not pass, explain reason for failures:

Process Checks

  • You have specified at least one "Reviewer".

@igoristic igoristic requested a review from stevenbarragan June 17, 2025 15:33
@igoristic igoristic self-assigned this Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant