# Why we need index template?

**URL:** <https://discuss.elastic.co/t/why-we-need-index-template/277523>\
**Category:** Kibana\
**Created:** [July 1, 2021, 7:38am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523 "2021-07-01T07:38:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nisha2297](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Nisha2297](https://discuss.elastic.co/u/Nisha2297)\
**Post date:** [July 1, 2021, 7:38am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/1 "2021-07-01T07:38:01Z")

</div>

Why we need to create index template when we can simply define the fields and there datatype in the logstash itself using below syntax:  
_mutate {convert =\> ["field\_name", "data\_type"]_

---

<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:** [July 1, 2021, 8:26am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/2 "2021-07-01T08:26:57Z")

</div>

Because Elasticsearch will still map it dynamically, not statically.

---

<div class="post-metadata">

**Author:** ![Nisha2297](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Nisha2297](https://discuss.elastic.co/u/Nisha2297)\
**Post date:** [July 1, 2021, 9:14am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/3 "2021-07-01T09:14:35Z")

</div>

Hi @warkolm ,  
Sorry but I am not able to clearly understand!.

---

<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:** [July 1, 2021, 9:20am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/4 "2021-07-01T09:20:25Z")

</div>

Even if you cast something in Logstash as, eg, a number, Elasticsearch might still map it as a string, or even the wrong kind of number type.

---

<div class="post-metadata">

**Author:** ![Nisha2297](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Nisha2297](https://discuss.elastic.co/u/Nisha2297)\
**Post date:** [July 1, 2021, 9:22am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/5 "2021-07-01T09:22:33Z")

</div>

Oh ok.  
I tried loading a csv file data from logstash and the integer type fields got mapped properly from Logstash mutate plugin. Thats when I got this question of why we can't directly do the index mapping in logstash config itself.

---

<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:** [July 1, 2021, 9:26am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/6 "2021-07-01T09:26:07Z")

</div>

Yep that will _probably_ work, but it's not a guarantee unless it's using a mapping in Elasticsearch.

---

<div class="post-metadata">

**Author:** ![Nisha2297](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Nisha2297](https://discuss.elastic.co/u/Nisha2297)\
**Post date:** [July 1, 2021, 9:26am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/7 "2021-07-01T09:26:51Z")

</div>

Thanks for all the clarification 🙂

---

<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 29, 2021, 9:27am UTC](https://discuss.elastic.co/t/why-we-need-index-template/277523/8 "2021-07-29T09:27:39Z")

</div>

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