# Elasticsearch API to add a lifecycle policy to an index template

**URL:** <https://discuss.elastic.co/t/elasticsearch-api-to-add-a-lifecycle-policy-to-an-index-template/173164>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management\
**Created:** [March 20, 2019, 2:07pm UTC](https://discuss.elastic.co/t/elasticsearch-api-to-add-a-lifecycle-policy-to-an-index-template/173164 "2019-03-20T14:07:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Russell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_russell/32/42429_2.png) [@Matt\_Russell](https://discuss.elastic.co/u/Matt_Russell)\
**Post date:** [March 20, 2019, 2:07pm UTC](https://discuss.elastic.co/t/elasticsearch-api-to-add-a-lifecycle-policy-to-an-index-template/173164/1 "2019-03-20T14:07:41Z")

</div>

Is there a way to update an index template to add a lifecycle policy through Elasticsearch APIs (to achieve the same effect as can be done in Kibana)?

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

---

<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:** [March 20, 2019, 2:29pm UTC](https://discuss.elastic.co/t/elasticsearch-api-to-add-a-lifecycle-policy-to-an-index-template/173164/2 "2019-03-20T14:29:32Z")

</div>

Hi Matt,

The only way you would do this with a template is to retrieve the template with

```auto
GET /_template/my-template

```

Then add the `index.lifecycle.name` setting to what already existed in the body of the template, and then update the template

```auto
PUT /_template/my-template
{
  "settings": {
    <... the rest of your template's settings ...>
    "index.lifecycle.name": "delete-old-logs"
  }
}
```

---

<div class="post-metadata">

**Author:** ![Matt\_Russell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_russell/32/42429_2.png) [@Matt\_Russell](https://discuss.elastic.co/u/Matt_Russell)\
**Post date:** [March 20, 2019, 2:57pm UTC](https://discuss.elastic.co/t/elasticsearch-api-to-add-a-lifecycle-policy-to-an-index-template/173164/3 "2019-03-20T14:57:15Z")

</div>

Thanks Lee - yeah, so I guess this is a bit awkward to script at present.

---

<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:** [April 17, 2019, 2:57pm UTC](https://discuss.elastic.co/t/elasticsearch-api-to-add-a-lifecycle-policy-to-an-index-template/173164/4 "2019-04-17T14:57:15Z")

</div>

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