# Delete indices after 180 days

**URL:** https://discuss.elastic.co/t/delete-indices-after-180-days/348148
**Category:** Logstash
**Tags:** ilm-index-lifecycle-management
**Created:** [November 28, 2023, 2:02pm UTC](https://discuss.elastic.co/t/delete-indices-after-180-days/348148 "2023-11-28T14:02:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![secsec](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@secsec](https://discuss.elastic.co/u/secsec)
#### Post date: [November 28, 2023, 2:02pm UTC](https://discuss.elastic.co/t/delete-indices-after-180-days/348148/1 "2023-11-28T14:02:57Z")

</div>

Hello,

i have create new ILM policy

```auto
PUT _ilm/policy/delete-logs-after-6months
{
  "policy": {
    "phases": {
      "delete": {
        "min_age": "180d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/a/5a3d20747bd24f38d0c75e24ee84cd5ea69dd00e.png)

and created index template and map to ILM policy

```auto
PUT /_index_template/template_delete-logs-after-6months
{
  "index_patterns": ["linux-*"],
  "template": {
    "settings": {
      "index": {
        "lifecycle": {
          "name": "delete-logs-after-6months"
        }
      }
    }
  }
}

```

![image](https://us1.discourse-cdn.com/elastic/original/3X/1/d/1dfeb5230bb0331f49f2798441abe7a8c8f0ce5c.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/a/2a20f6b61f115019d5beeadbb4cdc0f83ed7c3c0.png)

this my logstash output

```auto
output {
    if [host][os][type] == "windows" {
        elasticsearch {
            hosts => "https://somedomain.cz:9200"
            ssl_enabled => true
            ssl_key => "some.key"
            ssl_certificate => "certificate.crt"
            user => 'elastic'
            password => 'somepass'
            ssl_certificate_authorities => "ca.crt"
            manage_template => true
            template_name => "template_delete-logs-after-6months"
            index => "windows-%{[host][name]}-%{+YYYY.MM.dd}"
        }
    } else if [host][os][type] == "linux" {
        elasticsearch {
            hosts => "https://somedomain.cz:9200"
            user => 'elastic'
            password => 'somepass'
            ssl_enabled => true
            ssl_key => "some.key"
            ssl_certificate => "certificate.crt"
            ssl_certificate_authorities => "ca.crt"
            manage_template => true
            template_name => "template_delete-logs-after-6months"
            index => "linux-%{[host][name]}-%{+YYYY.MM.dd}"
        }
    } else {
        elasticsearch {
            hosts => "https://somedomain.cz:9200"
            user => 'elastic'
            password => 'somepass'
            data_stream => true
            ssl_enabled => true
            ssl_key => "some.key"
            ssl_certificate => "certificate.crt"
            ssl_certificate_authorities => "ca.crt"
        }
    }
}

```

creating new indexes are working but all created indexes are not mapped to "template\_delete-logs-after-6months"

how can i make sure that those templates new will be deleted after 6 months please?

im playing with values but no luck

```auto
manage_template => true
template_name => "template_delete-logs-after-6months"

```

and using Elastic 8.11

many thanks

---

<div class="post-metadata">

### Author: ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)
#### Post date: [November 29, 2023, 11:49am UTC](https://discuss.elastic.co/t/delete-indices-after-180-days/348148/2 "2023-11-29T11:49:44Z")

</div>

Hi @secsec,

I assume you're not seeing any errors with ILM at all, simialr to these in the [troubleshooting guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-error-handling.html)? Have you tried using the [`_explain` API](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html) to investigate the ILM settings on the impacted indexes?

---

<div class="post-metadata">

### Author: ![yago82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yago82/32/97755_2.png) [@yago82](https://discuss.elastic.co/u/yago82)
#### Post date: [November 29, 2023, 3:25pm UTC](https://discuss.elastic.co/t/delete-indices-after-180-days/348148/3 "2023-11-29T15:25:11Z")

</div>

hi,

for those previously existing indexes:

Go to the Index Management section in your Elasticsearch interface.  
Select the index that needs to adhere to the new lifecycle policy.  
Find the "Add lifecycle policy" option and apply the desired policy (template\_delete-logs-after-6months in your case) to ensure these indexes comply with the specified deletion timeframe.

---

<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: [December 27, 2023, 3:25pm UTC](https://discuss.elastic.co/t/delete-indices-after-180-days/348148/4 "2023-12-27T15:25:39Z")

</div>

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