# ILM how to delete index after days

**URL:** <https://discuss.elastic.co/t/ilm-how-to-delete-index-after-days/265490>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management\
**Created:** [February 25, 2021, 2:32pm UTC](https://discuss.elastic.co/t/ilm-how-to-delete-index-after-days/265490 "2021-02-25T14:32:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thewasta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thewasta/32/48818_2.png) [@thewasta](https://discuss.elastic.co/u/thewasta)\
**Post date:** [February 25, 2021, 2:32pm UTC](https://discuss.elastic.co/t/ilm-how-to-delete-index-after-days/265490/1 "2021-02-25T14:32:51Z")

</div>

My Enviroment

```auto
{
  "name" : "5D776AA",
  "cluster_name" : "rust-cluster",
  "cluster_uuid" : "unlQZ9RcTTy34WDJkHZ1wA",
  "version" : {
    "number" : "7.10.2",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
    "build_date" : "2021-01-13T00:42:12.435326Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

```

I am using Filebeat and Logstash to read a log file, this create a indices per day with name `rust-server-moded` (with YYYY.MM.DD), and I made a template for this index

```auto
    "index_patterns" : [
      "rust-server-*"
    ],

```

`GET rust-server-moded-2021.02.20/_ilm/explain`  
Returns

```auto
{
  "indices" : {
    "rust-server-moded-2021.02.20" : {
      "index" : "rust-server-moded-2021.02.20",
      "managed" : true,
      "policy" : "rust_server",
      "lifecycle_date_millis" : 1613779377709,
      "age" : "5.6d",
      "phase" : "hot",
      "phase_time_millis" : 1614263069063,
      "action" : "rollover",
      "action_time_millis" : 1613779975765,
      "step" : "check-rollover-ready",
      "step_time_millis" : 1614263069063,
      "is_auto_retryable_error" : true,
      "failed_step_retry_count" : 402,
      "phase_execution" : {
        "policy" : "rust_server",
        "phase_definition" : {
          "min_age" : "0ms",
          "actions" : {
            "rollover" : {
              "max_size" : "50gb",
              "max_age" : "3d"
            },
            "set_priority" : {
              "priority" : 100
            }
          }
        },
        "version" : 3,
        "modified_date_in_millis" : 1613979144386
      }
    }
  }
}

```

Shouldn't it be removed after 3 days?

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [February 25, 2021, 10:15pm UTC](https://discuss.elastic.co/t/ilm-how-to-delete-index-after-days/265490/2 "2021-02-25T22:15:40Z")

</div>

If you want to delete the index, you should add a delete action.  
[Example](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html)

```auto
PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "warm": {
        "min_age": "10d",
        "actions": {
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "delete": {
        "min_age": "30d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![thewasta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thewasta/32/48818_2.png) [@thewasta](https://discuss.elastic.co/u/thewasta)\
**Post date:** [February 26, 2021, 9:48am UTC](https://discuss.elastic.co/t/ilm-how-to-delete-index-after-days/265490/3 "2021-02-26T09:48:05Z")

</div>

This is what I did:

1. On dev-tool I pasted your policy with my conditions:

```auto
{
  "policy": {
    "phases": {
      "warm": {
        "min_age": "2d",
        "actions": {
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "delete": {
        "min_age": "3d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

```

1. Assign the new policy to my indices. It said me the actual indice has a policy and assign the new will overwrite, I accepted.

2. `GET rust-server-moded-2021.02.19/_ilm/explain` return

```auto
{
  "indices" : {
    "rust-server-moded-2021.02.19" : {
      "index" : "rust-server-moded-2021.02.19",
      "managed" : false
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [March 1, 2021, 12:09am UTC](https://discuss.elastic.co/t/ilm-how-to-delete-index-after-days/265490/4 "2021-03-01T00:09:39Z")

</div>

If you’ve been using Curator or some other mechanism to manage periodic indices, you have a couple options when migrating to ILM:

- Set up your index templates to use an ILM policy to manage your new indices. Once ILM is managing your current write index, you can apply an appropriate policy to your old indices.
- Reindex into an ILM-managed index.

> **[Manage existing indices | Elasticsearch Reference \[7.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-with-existing-indices.html)**

---

<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 29, 2021, 12:10am UTC](https://discuss.elastic.co/t/ilm-how-to-delete-index-after-days/265490/5 "2021-03-29T00:10:24Z")

</div>

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