# Ilm policy for existing index

**URL:** <https://discuss.elastic.co/t/ilm-policy-for-existing-index/282036>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management\
**Created:** [August 20, 2021, 5:10am UTC](https://discuss.elastic.co/t/ilm-policy-for-existing-index/282036 "2021-08-20T05:10:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IsAa](https://avatars.discourse-cdn.com/v4/letter/i/6bbea6/32.png) [@IsAa](https://discuss.elastic.co/u/IsAa)\
**Post date:** [August 20, 2021, 5:10am UTC](https://discuss.elastic.co/t/ilm-policy-for-existing-index/282036/1 "2021-08-20T05:10:39Z")

</div>

Hi Team,

I am trying to understand how does ilm policy also setup new indices.

I understand that one needs to first setup the ilm policy which is then assigned to a template e.g

```auto
{
  "index_patterns": ["test-*"], 
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1,
      "index.lifecycle.name": "my_ilm_policy", 
      "index.lifecycle.rollover_alias": "my_ilm_policy" 
    }
  }
}

```

As you can observe that this has a lifecycle name and roll\_over alias  
If I now wanted to apply this policy to an existing index, which I have written like this

```auto
output {
  #stdout { codec => rubydebug { metadata => true }}
  elasticsearch {
    hosts => "${ELASTIC_HOST}"
    index => "test-"
    user => "${ELASTIC_USER}"
    password => "${ELASTIC_PWD}"
	document_type => "sqltest"
	document_id => "%{id}"
  }  
}

```

does that mean I am no longer required to provide index and just enable the ilm policy and it takes care of the index generation

```auto
elasticsearch {
        hosts => "${ELASTIC_HOST}"
        user => "${ELASTIC_USER}"
        password => "${ELASTIC_PWD}"
        document_id => "%{id}"
        ilm_enabled => true
        ilm_rollover_alias => "test_ilm"
        ilm_pattern => "000001"
        ilm_policy => "my_ilm_policy"
    }

```

And if yes.  
Then what happens to my older indices, can I just reindex them

```auto
POST _reindex
{
  "source": {
    "index": "test-"
  },
  "dest": {
    "index": "test_ilm-000001"
  }
}

```

Sorry for the long post, I am getting confused how does ilm policy help in creating indices with patterns eg. idex-0001,index002 so that it knows when to send that index pattern to a delete stage  
Does the new index patterns get generated when a new document has become part of the index ?

Thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 20, 2021, 5:29am UTC](https://discuss.elastic.co/t/ilm-policy-for-existing-index/282036/2 "2021-08-20T05:29:08Z")

</div>

> [@IsAa](#):
>
> does that mean I am no longer required to provide index and just enable the ilm policy and it takes care of the index generation

Yep!

> [@IsAa](#):
>
> Then what happens to my older indices, can I just reindex them

Also yep! Or just manually delete them after a period of time.

---

<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:** [September 17, 2021, 5:29am UTC](https://discuss.elastic.co/t/ilm-policy-for-existing-index/282036/3 "2021-09-17T05:29:40Z")

</div>

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