# How do I add a lifecycle policy to an index via the API?

**URL:** <https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management\
**Created:** [November 4, 2020, 3:36pm UTC](https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295 "2020-11-04T15:36:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmcclelland](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jmcclelland](https://discuss.elastic.co/u/jmcclelland)\
**Post date:** [November 4, 2020, 3:36pm UTC](https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295/1 "2020-11-04T15:36:41Z")

</div>

In Kibana, if I click on an index, and then click the Manage button, I have the option to "Add lifecycle policy" to that existing index - I'm asked for the policy to add and the rollover index.

How do I do this via the API?

I see [documentation on how to remove a policy](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-remove-policy.html) but nothing on how to add one.

Thanks!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 4, 2020, 4:26pm UTC](https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295/2 "2020-11-04T16:26:23Z")

</div>

Isn't this page?

> **[Create lifecycle policy API | Elasticsearch Reference \[7.9\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html)**

---

<div class="post-metadata">

**Author:** ![jmcclelland](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jmcclelland](https://discuss.elastic.co/u/jmcclelland)\
**Post date:** [November 4, 2020, 4:44pm UTC](https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295/3 "2020-11-04T16:44:58Z")

</div>

Thanks for getting back to me. I just updated my question to make it clearer - that page describes how to add a life cycle policy. I'm trying to figure out how to add an existing lifecycle policy to an existing index

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 4, 2020, 4:52pm UTC](https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295/4 "2020-11-04T16:52:38Z")

</div>

It's an index settings. So you need to call the [update index settings API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html) or the [index template API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-template.html). Of course this also works with the [create index API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html).

See [https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-settings.html#\_index\_level\_settings](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-settings.html#_index_level_settings)

Specifically `index.lifecycle.name`.

---

<div class="post-metadata">

**Author:** ![jmcclelland](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jmcclelland](https://discuss.elastic.co/u/jmcclelland)\
**Post date:** [November 4, 2020, 4:56pm UTC](https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295/5 "2020-11-04T16:56:12Z")

</div>

Thank you!! That looks like it's exactly what I need.

---

<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 2, 2020, 4:56pm UTC](https://discuss.elastic.co/t/how-do-i-add-a-lifecycle-policy-to-an-index-via-the-api/254295/6 "2020-12-02T16:56:13Z")

</div>

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