# Create Index Lifecycle Policies to existing index

**URL:** <https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983>\
**Category:** Kibana\
**Tags:** ilm-index-lifecycle-management\
**Created:** [December 5, 2021, 12:57pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983 "2021-12-05T12:57:35Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 5, 2021, 12:57pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/1 "2021-12-05T12:57:35Z")

</div>

Hi,  
im trying to add 'Index Lifecycle Policies' to my existing index.  
my steps:  
Index management --\> choose my index --\> add lifecycle policy --\> slect logs  
but i got  
'Policy logs is configured for rollover, but index my\_index does not have an alias, which is required for rollover.'  
how did i add an alias to my index? **and what should be the alias?**

---

<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:** [December 6, 2021, 1:12am UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/2 "2021-12-06T01:12:19Z")

</div>

Does [Configure a lifecycle policy | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/set-up-lifecycle-policy.html) help?

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 6, 2021, 7:50am UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/3 "2021-12-06T07:50:17Z")

</div>

i already tried to do it, i created a template but still don't understand what should be the alias...

---

<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:** [December 6, 2021, 8:13am UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/4 "2021-12-06T08:13:48Z")

</div>

It might be useful if you shared the settings you are using.

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 7, 2021, 7:31am UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/5 "2021-12-07T07:31:09Z")

</div>

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

so,  
i tried to create my own 'index template' but still:

1. don't know what should be the alias  
2.did my index template need to be rollover? how to disable this option if not?

---

<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:** [December 7, 2021, 8:24pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/6 "2021-12-07T20:24:24Z")

</div>

Please share your full config.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [December 7, 2021, 8:35pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/7 "2021-12-07T20:35:02Z")

</div>

I had same problem when I first started setting this up. didn't understand it.

It is three step proces. create ILM, create template, create index

```auto

## create ILM
PUT _ilm/policy/my_monitoring
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "rollover": {
            "max_age": "30d",
            "max_size": "50gb"
          },
          "set_priority": {
            "priority": 100
          }
        }
      }
    }
  }
}

## Create template, you can change this latter for shard etc..
PUT _index_template/my_monitoring
{
  "index_patterns": ["my_monitoring-*"],
  "template": {
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 0,
      "index.lifecycle.name": "my_monitoring",
      "index.lifecycle.rollover_alias": "my_monitoring"
    }
  }
}

## Create alias
## after this write your data only to my_monitoring and it will create proper date-000001 index
## This actually creates blank index my_monitoring-2021-07-14-000001

# PUT <my-index-{now/d}-000001>
PUT %3Cmy_monitoring-%7Bnow%2Fd%7D-000001%3E
{
  "aliases": {
    "my_monitoring": {
      "is_write_index": true
    }
  }
}

```

What will happen here is that, it will create new index called my\_monitoring-date-000001  
and in your logstash/python whereever you now use my\_monitoring to write to.

and ILM will rotate index when time comes and will create new index called my\_monitoring-date-000002 but your logstash/python will keep writing to my\_monitoring

now basically my\_monitoring -\> my\_monitoring-date-000002 ( which was 01 before) ILM will do this for you.

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 8, 2021, 10:16am UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/8 "2021-12-08T10:16:54Z")

</div>

Thanks a lot!!!  
im having some issues:  
i followd all your steps and when trying to set the alias (step #3), i got an error 'an index or data stream exists with the same name as the alias'  
so i changed the alias name and its worked.  
but now i got the following error:

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

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [December 8, 2021, 2:10pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/9 "2021-12-08T14:10:26Z")

</div>

> [@Aviel\_Bashari](#):
>
> name as the alias'

because you already have that index exist.

is this brand new setup or setting up in existing index?

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 8, 2021, 3:17pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/10 "2021-12-08T15:17:23Z")

</div>

existing one

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [December 8, 2021, 4:56pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/11 "2021-12-08T16:56:39Z")

</div>

ok then give me more info  
what is your existing index name?

what are the command you executed? full list

for testing you can run all three code with some dummy indexname. once you satisfy and understand this you can remove ILM, and index and alias.

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 8, 2021, 5:12pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/12 "2021-12-08T17:12:29Z")

</div>

ok so,  
index name: jenkins\_jobs\_logs  
the commands are the same as you mentioned above just replace 'my\_monitoring' with 'jenkins\_jobs\_logs':

```auto
## create ILM
PUT _ilm/policy/jenkins_jobs_logs
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "rollover": {
            "max_age": "30d",
            "max_size": "50gb"
          },
          "set_priority": {
            "priority": 100
          }
        }
      }
    }
  }
}

## Create template, you can change this latter for shard etc..
PUT _index_template/my_monitoring
{
  "index_patterns": ["jenkins_jobs_logs-*"],
  "template": {
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 0,
      "index.lifecycle.name": "jenkins_jobs_logs",
      "index.lifecycle.rollover_alias": "jenkins_jobs_logs"
    }
  }
}

## Create alias
## after this write your data only to my_monitoring and it will create proper date-000001 index
## This actually creates blank index my_monitoring-2021-07-14-000001

# PUT <my-index-{now/d}-000001>
PUT %3Cjenkins_jobs_logs-%7Bnow%2Fd%7D-000001%3E
{
  "aliases": {
    "jenkins_jobs_logs": {
      "is_write_index": true
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [December 8, 2021, 8:00pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/13 "2021-12-08T20:00:07Z")

</div>

and what is index name you have in your index management window?

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 9, 2021, 7:47am UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/14 "2021-12-09T07:47:02Z")

</div>

the same name - 'jenkins\_jobs\_logs'

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [December 9, 2021, 3:25pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/15 "2021-12-09T15:25:24Z")

</div>

that is your problem. your index should be jenkins\_jobs\_logs--000001  
because jenkins\_jobs\_logs is now alias points to  
jenkins\_jobs\_logs -\> jenkins\_jobs\_logs--000001

and when ILM runs it will create new index called "jenkins\_jobs\_logs--000002  
and now your alias will pint to new index and old index will become read only  
jenkins\_jobs\_logs -\> jenkins\_jobs\_logs--000002

and you only write to one "jenkins\_job\_logs"

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 15, 2021, 10:02am UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/16 "2021-12-15T10:02:42Z")

</div>

ok so all i need is to rename my index to jenkins\_jobs\_logs-000001 ?

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [December 15, 2021, 1:01pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/17 "2021-12-15T13:01:01Z")

</div>

yes

also check  
GET /\_cat/aliases and you should see jenkins\_jobs\_logs

---

<div class="post-metadata">

**Author:** ![Aviel\_Bashari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviel_bashari/32/92464_2.png) [@Aviel\_Bashari](https://discuss.elastic.co/u/Aviel_Bashari)\
**Post date:** [December 15, 2021, 3:08pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/18 "2021-12-15T15:08:17Z")

</div>

thanks a lot!!!

---

<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:** [January 12, 2022, 3:09pm UTC](https://discuss.elastic.co/t/create-index-lifecycle-policies-to-existing-index/290983/19 "2022-01-12T15:09:09Z")

</div>

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