# Dynamic index name with template setup fails on using an existing ILM

**URL:** <https://discuss.elastic.co/t/dynamic-index-name-with-template-setup-fails-on-using-an-existing-ilm/243242>\
**Category:** Elastic Cloud on Kubernetes (ECK)\
**Created:** [July 30, 2020, 2:48pm UTC](https://discuss.elastic.co/t/dynamic-index-name-with-template-setup-fails-on-using-an-existing-ilm/243242 "2020-07-30T14:48:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raulgs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raulgs/32/68308_2.png) [@raulgs](https://discuss.elastic.co/u/raulgs)\
**Post date:** [July 30, 2020, 2:48pm UTC](https://discuss.elastic.co/t/dynamic-index-name-with-template-setup-fails-on-using-an-existing-ilm/243242/1 "2020-07-30T14:48:03Z")

</div>

Hi guys,

I am currently trying to define a ILM that should be used for a specific template.  
However, I am failing unfortunately.

The manifest looks like that:

```auto
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
  name: filebeat
spec:
  type: filebeat
  version: 7.8.1
  elasticsearchRef:
    name: elastic
    namespace: elastic-system
    # Currently this setting requires Kibana to have TLS enabled.
    # See https://github.com/elastic/cloud-on-k8s/issues/3523 for more information.
  kibanaRef:
    name: kibana
    namespace: elastic-system
  config:
    output.elasticsearch.index: "%{[kubernetes.namespace]}-filebeat-%{+xxxx.ww}"
    output.elasticsearch.username: "filebeat"
    output.elasticsearch.password: "xyz"
    setup.template.name: "filebeat"
    setup.template.pattern: "*"
    setup.template.overwrite: true
    setup.template.settings:
      index.number_of_shards: 3
      index.number_of_replicas: 1
    setup.ilm.enabled: false
    setup.ilm.policy_name: "denic-index-policy"
    setup.dashboards.enabled: true

```

As you can see the template `filebeat` will be create / overwritten everytime I deploy this manifest. With that a pattern selector for all indicies will be set. What I am failing now is to set the ILM that this template should use. I have a self build ILM in place, that should be attached to this template. However, it seems like `setup.ilm.enabled: false` disables the whole ILM usage for the template. I already tried using `auto` and `enabled`. When using them, the ILM gets set but `output.elasticsearch.index` will be ignored.

Any idea?

---

<div class="post-metadata">

**Author:** ![dkow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkow/32/47340_2.png) [@dkow](https://discuss.elastic.co/u/dkow)\
**Post date:** [July 30, 2020, 4:18pm UTC](https://discuss.elastic.co/t/dynamic-index-name-with-template-setup-fails-on-using-an-existing-ilm/243242/2 "2020-07-30T16:18:30Z")

</div>

Hi @raulgs, thanks for your question.

I think that is the expected behaviour - see [Index lifecycle management](https://www.elastic.co/guide/en/beats/filebeat/current/ilm.html):

> If [index lifecycle management](https://www.elastic.co/guide/en/beats/filebeat/current/ilm.html) is enabled (which is typically the default), `setup.template.name` and `setup.template.pattern` are ignored.

and [filebeat-reference.yml](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-reference-yml.html):

```yaml
# Configure index lifecycle management (ILM). These settings create a write
# alias and add additional settings to the index template. When ILM is enabled,
# output.elasticsearch.index is ignored, and the write alias is used to set the
# index name.

```

As to the why this is the case or if you have any other questions on this particular subject, the [Beats forum](https://discuss.elastic.co/c/elastic-stack/beats/28) would be the best place to ask.

---

<div class="post-metadata">

**Author:** ![raulgs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raulgs/32/68308_2.png) [@raulgs](https://discuss.elastic.co/u/raulgs)\
**Post date:** [July 31, 2020, 9:45am UTC](https://discuss.elastic.co/t/dynamic-index-name-with-template-setup-fails-on-using-an-existing-ilm/243242/3 "2020-07-31T09:45:44Z")

</div>

Alright I just figured out that this works as well

```auto
    setup.template.enabled: true
    setup.template.name: "filebeat-%{[agent.version]}"
    setup.template.pattern: "*-filebeat-*"
    setup.template.order: 50
    setup.template.overwrite: true
    setup.template.settings:
      index.number_of_shards: 3
      index.number_of_replicas: 1
      index.lifecycle.name: "denic-index-policy"

```

So I am fine. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![dkow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkow/32/47340_2.png) [@dkow](https://discuss.elastic.co/u/dkow)\
**Post date:** [July 31, 2020, 1:47pm UTC](https://discuss.elastic.co/t/dynamic-index-name-with-template-setup-fails-on-using-an-existing-ilm/243242/4 "2020-07-31T13:47:00Z")

</div>

That's great to hear, thanks for the update.

---

<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:** [November 4, 2022, 8:08am UTC](https://discuss.elastic.co/t/dynamic-index-name-with-template-setup-fails-on-using-an-existing-ilm/243242/5 "2022-11-04T08:08:20Z")

</div>


