Setup hot-delete policy for Elastichsearch index without using templates

I'm trying to setup an ILM policy that deletes my index every 3 days, and creates a new one. Here's my attempt for achieving that:

  const policyName = "hot_delete_twitter_stream_indexing_policy"

  await ESClient.ilm.putLifecycle({
    policy: policyName,
    body: {
      policy: {
        phases: {
          hot: {
            actions: {
              rollover: {
                max_age: "30s",
              },
            },
          },
          delete: {
            actions: {
              delete: {},
            },
          },
        },
      },
    },
  })

  const rolloverIndexAliasName = `${process.env.ES_INDEX}_rollover_index`

  await ESClient.indices.create({
    index: process.env.ES_INDEX,
    body: {
      settings: {
        "index.lifecycle.name": policyName,
        "index.lifecycle.rollover_alias": rolloverIndexAliasName,
      },
      mappings: {
        properties: {
          author_username: { type: "keyword" },
          id: { type: "keyword" },
          timestamp: { type: "keyword" },
          text: { type: "text" },
          bounding_box: { type: "geo_shape" },
        },
      },
    },
  })

  await ESClient.indices.putAlias({
    index: process.env.ES_INDEX,
    name: rolloverIndexAliasName,
  })

Executing this code, when I add records to my index, and check the ILM explain endpoint after 30 seconds to check if my index is deleted, the index is still there, and I still can add records to it.

Here's the output of the ILM explain endpoint:

{
    "indices": {
        "expotwitt_tweets": {
            "index": "expotwitt_tweets",
            "managed": true,
            "policy": "hot_delete_twitter_stream_indexing_policy",
            "lifecycle_date_millis": 1638980335786,
            "age": "20.71s",
            "phase": "hot",
            "phase_time_millis": 1638980335933,
            "action": "rollover",
            "action_time_millis": 1638980335933,
            "step": "check-rollover-ready",
            "step_time_millis": 1638980335933,
            "phase_execution": {
                "policy": "hot_delete_twitter_stream_indexing_policy",
                "phase_definition": {
                    "min_age": "0ms",
                    "actions": {
                        "rollover": {
                            "max_age": "30s"
                        }
                    }
                },
                "version": 2,
                "modified_date_in_millis": 1638980335739
            }
        }
    }
}

And it remains the same after 30 seconds has passed.

Can you spot what am I doing wrong, or if there is an entirely different but better approach to achieve my goal described above? Thank you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.