# Dynamic template vs Index template with explicit mapping in terms of performance

**URL:** <https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399>\
**Category:** Elasticsearch\
**Created:** [November 21, 2022, 8:39am UTC](https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399 "2022-11-21T08:39:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![2019240081](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/2019240081/32/107281_2.png) [@2019240081](https://discuss.elastic.co/u/2019240081)\
**Post date:** [November 21, 2022, 8:39am UTC](https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399/1 "2022-11-21T08:39:34Z")

</div>

Considering both search response speed and indexing rate (in my case the latter is more important ), which is more efficient? Dynamic template or Index template with explicit mapping ? It depends on my environment?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 21, 2022, 9:44am UTC](https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399/2 "2022-11-21T09:44:49Z")

</div>

It has no impact on query performance. When it comes to indexing dynamic mappings allows new fields to be added over time. Each time a new field is added the cluster state need to be updated. Adding a lot of new fields can therefore slow down indexing. If you however are not adding new fields there should not be any performance difference at all.

---

<div class="post-metadata">

**Author:** ![2019240081](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/2019240081/32/107281_2.png) [@2019240081](https://discuss.elastic.co/u/2019240081)\
**Post date:** [November 22, 2022, 12:32am UTC](https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399/3 "2022-11-22T00:32:23Z")

</div>

@Christian_Dahlqvist Does dynamic "template" need more resource when indexing like dynamic mapping does? I thought dynamic template defines match\_mapping\_type or matching prefix of field before indexing so it is more efficient than dynamic "mapping"

there are no difference between them?

---

<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:** [November 22, 2022, 12:35am UTC](https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399/4 "2022-11-22T00:35:33Z")

</div>

Technically yes, dynamic needs more resources as Elasticsearch needs to parse the field the first time it sees it and then tries to match it to one of the field types, so there's a computational cost there.

In practise, the overhead isn't worth worrying about and I don't even think we've measured it.

---

<div class="post-metadata">

**Author:** ![linkerc](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@linkerc](https://discuss.elastic.co/u/linkerc)\
**Post date:** [November 22, 2022, 12:42am UTC](https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399/5 "2022-11-22T00:42:01Z")

</div>

Only for the first time. Once the field is dynamically selected, it'll be fixed to that type in \_mappings forever (life time of that index).  
So indexing performance downside will be negligible per @warkolm.

---

<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:** [December 20, 2022, 12:42am UTC](https://discuss.elastic.co/t/dynamic-template-vs-index-template-with-explicit-mapping-in-terms-of-performance/319399/6 "2022-12-20T00:42:03Z")

</div>

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