# Logstash Dynamic Template and ILM Creation

**URL:** <https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653>\
**Category:** Logstash\
**Created:** [August 27, 2020, 3:15pm UTC](https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653 "2020-08-27T15:15:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramalakshmi](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ramalakshmi](https://discuss.elastic.co/u/Ramalakshmi)\
**Post date:** [August 27, 2020, 3:15pm UTC](https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653/1 "2020-08-27T15:15:23Z")

</div>

Hi

I am able to create the multiple index patterns dynamically using below configuration.

```
    output {
      stdout { codec => rubydebug }
      elasticsearch {
       hosts => [es_host:9200"]
        index => "lstash-%{[event][class]}"
      }
    }

```

After that I have added below template and ilm settings in output block for creating templates and ilms for those indexes.

template =\> "/opt/elk/logstash/config/templates/lstash-%{[event][class]}-template.json"  
template\_name =\> "lstash-%{[event][class]}-template"  
template\_overwrite =\> true  
ilm\_enabled =\> true  
ilm\_rollover\_alias =\> "lstash-%{[event][class]}-"  
ilm\_pattern =\> "000001"  
ilm\_policy =\> "custom-policy"

Then run the logstash service,showing below error

```
    output {
        elasticsearch {
          # This setting must be a path
          # File does not exist or cannot be opened /opt/elk/logstash/config/templates/lstash-%{[event][class]}-template.json
          template => "/opt/elk/logstash/config/templates/lstash-%{[event][class]}-template.json"
          ...
        }
      }
```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 27, 2020, 3:28pm UTC](https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653/2 "2020-08-27T15:28:26Z")

</div>

My reading of the [code](https://github.com/logstash-plugins/logstash-output-elasticsearch/blob/master/lib/logstash/outputs/elasticsearch/template_manager.rb#L1) is that the template manager never sprintf's the template option, so you cannot use a field reference in it.

---

<div class="post-metadata">

**Author:** ![Ramalakshmi](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ramalakshmi](https://discuss.elastic.co/u/Ramalakshmi)\
**Post date:** [August 27, 2020, 3:41pm UTC](https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653/3 "2020-08-27T15:41:58Z")

</div>

ok, we can't create dynamic templates for multiple indexes?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 27, 2020, 3:46pm UTC](https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653/4 "2020-08-27T15:46:32Z")

</div>

That is my reading of it.

---

<div class="post-metadata">

**Author:** ![Ramalakshmi](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ramalakshmi](https://discuss.elastic.co/u/Ramalakshmi)\
**Post date:** [August 27, 2020, 3:50pm UTC](https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653/5 "2020-08-27T15:50:35Z")

</div>

Any possible way to create the dynamic templates.  
Please help me on this.

---

<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 24, 2020, 3:50pm UTC](https://discuss.elastic.co/t/logstash-dynamic-template-and-ilm-creation/246653/6 "2020-09-24T15:50:42Z")

</div>

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