# Multiple templates in one logstash.conf

**URL:** <https://discuss.elastic.co/t/multiple-templates-in-one-logstash-conf/46230>\
**Category:** Elasticsearch\
**Created:** [April 4, 2016, 11:39am UTC](https://discuss.elastic.co/t/multiple-templates-in-one-logstash-conf/46230 "2016-04-04T11:39:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandhya\_Rathinapandi](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Sandhya\_Rathinapandi](https://discuss.elastic.co/u/Sandhya_Rathinapandi)\
**Post date:** [April 4, 2016, 11:39am UTC](https://discuss.elastic.co/t/multiple-templates-in-one-logstash-conf/46230/1 "2016-04-04T11:39:41Z")

</div>

Hi,

I am trying to use multiple templates for the indexes in the output section in logstash.conf, but it is always ignoring one of the templates.  
Sample conf:  
output {  
if [type] == "log1" {  
elasticsearch { hosts =\> ["localhost:9200"]  
index =\> "sample1-%{+MM.YYYY}"  
template =\> "/root/logstash-2.2.2/log1.json"  
manage\_template =\> true  
template\_overwrite =\> true  
}  
}  
if [type] == "log2" {  
elasticsearch { hosts =\> ["localhost:9200"]  
index =\> "sample2-%{+MM.YYYY}"  
template =\> "/root/logstash-2.2.2/log2.json"  
manage\_template =\> true  
template\_overwrite =\> true  
}  
}  
}

Also suggest me a good example for this kind of configuration.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 4, 2016, 11:55am UTC](https://discuss.elastic.co/t/multiple-templates-in-one-logstash-conf/46230/2 "2016-04-04T11:55:12Z")

</div>

Both outputs are storing the templates under the same name ("logstash"). Use the elasticsearch output's `template_name` option to pick a unique template name for each output (e.g. "log1" and "log2" to match the index template filenames).

---

<div class="post-metadata">

**Author:** ![Sandhya\_Rathinapandi](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Sandhya\_Rathinapandi](https://discuss.elastic.co/u/Sandhya_Rathinapandi)\
**Post date:** [April 19, 2016, 5:26am UTC](https://discuss.elastic.co/t/multiple-templates-in-one-logstash-conf/46230/3 "2016-04-19T05:26:36Z")

</div>

Thank you so much and this worked.

---

<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:** [July 5, 2017, 10:58pm UTC](https://discuss.elastic.co/t/multiple-templates-in-one-logstash-conf/46230/4 "2017-07-05T22:58:16Z")

</div>


