# Index Lifecycle Policy Not Deleting Indices

**URL:** <https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880>\
**Category:** Kibana\
**Tags:** ilm-index-lifecycle-management\
**Created:** [January 19, 2022, 10:43pm UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880 "2022-01-19T22:43:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Dooley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_dooley/32/101152_2.png) [@Brandon\_Dooley](https://discuss.elastic.co/u/Brandon_Dooley)\
**Post date:** [January 19, 2022, 10:43pm UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880/1 "2022-01-19T22:43:29Z")

</div>

I have an index lifecycle policy set up which I want to delete indices after 30 days. In order to achieve this the policy has two phases:

1. **Hot Phase** (with 'Delete data after this phase' selected)

 ![Screenshot 2022-01-19 at 22.39.38](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ad6b1fff98a5b185e9ce6d51a90ee7ae0bff951.png)

1. **Delete Phase** (indices moved here 30 days after creation)

 ![Screenshot 2022-01-19 at 22.40.09](https://us1.discourse-cdn.com/elastic/original/3X/c/8/c8d6e3b8b8a6f68eb6529ce0ce4d024c5cef3c1d.png)

The Elasticsearch request displayed in the UI to create this policy is as follows:

```auto
PUT _ilm/policy/bounce-logs-rollover-30-days
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "set_priority": {
            "priority": 100
          }
        }
      },
      "delete": {
        "min_age": "30d",
        "actions": {
          "wait_for_snapshot": {
            "policy": "bounce-daily-snapshots"
          },
          "delete": {
            "delete_searchable_snapshot": true
          }
        }
      }
    }
  }
}

```

As far as I can tell everything is set up correctly. The snapshot policy which is being waited upon is also executing successfully. However, when I search through my indices I am finding indices older than 30 days still existing and am having to manually delete them.

This index policy is attached to 5 index templates which is linked to ~400 indices. You can see an example of the index template attachment below:

 ![Screenshot 2022-01-19 at 22.42.36](https://us1.discourse-cdn.com/elastic/original/3X/c/6/c6914824af0cb6b9ce7ce4014338089efe2de7d9.png)

**Note** : I don't want to perform any rollover to any other phases, just a straightforward deletion of indices after 30 days.

---

<div class="post-metadata">

**Author:** ![Brandon\_Dooley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_dooley/32/101152_2.png) [@Brandon\_Dooley](https://discuss.elastic.co/u/Brandon_Dooley)\
**Post date:** [February 1, 2022, 12:23pm UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880/2 "2022-02-01T12:23:21Z")

</div>

Anyone have any idea?

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [February 1, 2022, 3:05pm UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880/3 "2022-02-01T15:05:46Z")

</div>

Can you post the explain output for one of the indices? You can get it with:

```auto
GET /<index-name>/_ilm/explain?human

```

---

<div class="post-metadata">

**Author:** ![Brandon\_Dooley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_dooley/32/101152_2.png) [@Brandon\_Dooley](https://discuss.elastic.co/u/Brandon_Dooley)\
**Post date:** [February 1, 2022, 4:06pm UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880/4 "2022-02-01T16:06:23Z")

</div>

Hi Lee,

Please find below the explain output for the index `prod-api-logs-2022.01.01` (more than 30 days old and should have been deleted by the policy)

```auto
{
  "indices" : {
    "prod-api-logs-2022.01.01" : {
      "index" : "prod-api-logs-2022.01.01",
      "managed" : true,
      "policy" : "bounce-logs-rollover-30-days",
      "lifecycle_date" : "2022-01-01T00:00:00.365Z",
      "lifecycle_date_millis" : 1640995200365,
      "age" : "31.66d",
      "phase" : "hot",
      "phase_time" : "2022-01-11T12:34:03.322Z",
      "phase_time_millis" : 1641904443322,
      "action" : "rollover",
      "action_time" : "2022-01-01T00:00:03.168Z",
      "action_time_millis" : 1640995203168,
      "step" : "check-rollover-ready",
      "step_time" : "2022-01-11T12:34:03.322Z",
      "step_time_millis" : 1641904443322,
      "is_auto_retryable_error" : true,
      "failed_step_retry_count" : 758,
      "phase_execution" : {
        "policy" : "bounce-logs-rollover-30-days",
        "phase_definition" : {
          "min_age" : "0ms",
          "actions" : {
            "set_priority" : {
              "priority" : 100
            }
          }
        },
        "version" : 6,
        "modified_date" : "2022-01-11T12:26:41.119Z",
        "modified_date_in_millis" : 1641904001119
      }
    }
  }
}

```

For a newish index (`prod-api-logs-2022.01.28`) please see below:

```auto
{
  "indices" : {
    "prod-api-logs-2022.01.28" : {
      "index" : "prod-api-logs-2022.01.28",
      "managed" : true,
      "policy" : "bounce-logs-rollover-30-days",
      "lifecycle_date" : "2022-01-28T00:00:06.073Z",
      "lifecycle_date_millis" : 1643328006073,
      "age" : "4.67d",
      "phase" : "hot",
      "phase_time" : "2022-01-28T00:00:07.206Z",
      "phase_time_millis" : 1643328007206,
      "action" : "complete",
      "action_time" : "2022-01-28T00:00:08.207Z",
      "action_time_millis" : 1643328008207,
      "step" : "complete",
      "step_time" : "2022-01-28T00:00:08.207Z",
      "step_time_millis" : 1643328008207,
      "phase_execution" : {
        "policy" : "bounce-logs-rollover-30-days",
        "phase_definition" : {
          "min_age" : "0ms",
          "actions" : {
            "set_priority" : {
              "priority" : 100
            }
          }
        },
        "version" : 6,
        "modified_date" : "2022-01-11T12:26:41.119Z",
        "modified_date_in_millis" : 1641904001119
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [February 1, 2022, 11:30pm UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880/5 "2022-02-01T23:30:33Z")

</div>

Okay, this sounds like you hit this bug: [ILM: Retrying a failed step refreshes the cached ILM phase · Issue #81921 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/81921) which was fixed in 7.17.0+ in [ILM step retry safe refresh of the cached phase by andreidan · Pull Request #82613 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/pull/82613).

Your newer indices doesn't have this problem, as it originally stemmed from the older index being in the rollover step, which had an error, and then the rollover was removed from your ILM policy (which means new indices will not suffer from this problem).

To fix that index in particular, you'll need to use move-to-step, which I would recommend with the following:

```auto
POST /_ilm/move/prod-api-logs-2022.01.01
{
  "current_step": {
    "phase": "hot",
    "action": "rollover",
    "name": "check-rollover-ready"
  },
  "next_step": {
    "phase": "hot",
    "action": "complete",
    "name": "complete"
  }
}

```

---

<div class="post-metadata">

**Author:** ![Brandon\_Dooley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_dooley/32/101152_2.png) [@Brandon\_Dooley](https://discuss.elastic.co/u/Brandon_Dooley)\
**Post date:** [February 16, 2022, 9:54am UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880/6 "2022-02-16T09:54:44Z")

</div>

You were spot on. Seems to be rolling over my indices fine now, 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:** [March 16, 2022, 9:55am UTC](https://discuss.elastic.co/t/index-lifecycle-policy-not-deleting-indices/294880/7 "2022-03-16T09:55:11Z")

</div>

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