# Setup hot-delete policy for Elastichsearch index without using templates

**URL:** https://discuss.elastic.co/t/setup-hot-delete-policy-for-elastichsearch-index-without-using-templates/291242
**Category:** Elasticsearch
**Tags:** ilm-index-lifecycle-management
**Created:** [December 8, 2021, 4:24pm UTC](https://discuss.elastic.co/t/setup-hot-delete-policy-for-elastichsearch-index-without-using-templates/291242 "2021-12-08T16:24:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![obadakhalili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/obadakhalili/32/98562_2.png) [@obadakhalili](https://discuss.elastic.co/u/obadakhalili)
#### Post date: [December 8, 2021, 4:24pm UTC](https://discuss.elastic.co/t/setup-hot-delete-policy-for-elastichsearch-index-without-using-templates/291242/1 "2021-12-08T16:24:16Z")

</div>

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:

```auto
  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:

```json
{
    "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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 5, 2022, 4:25pm UTC](https://discuss.elastic.co/t/setup-hot-delete-policy-for-elastichsearch-index-without-using-templates/291242/2 "2022-01-05T16:25:13Z")

</div>

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