# Question About Dynamically Generated Keyword Fields

**URL:** <https://discuss.elastic.co/t/question-about-dynamically-generated-keyword-fields/97815>\
**Category:** Elasticsearch\
**Created:** [August 21, 2017, 6:58pm UTC](https://discuss.elastic.co/t/question-about-dynamically-generated-keyword-fields/97815 "2017-08-21T18:58:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [August 21, 2017, 6:58pm UTC](https://discuss.elastic.co/t/question-about-dynamically-generated-keyword-fields/97815/1 "2017-08-21T18:58:53Z")

</div>

I am getting ready to make the jump from 2.4 to 5.X and see that string fields are now dynamically mapped as both a text and keyword field by default. My question is, does it hurt anything to leave the keyword field in place even though I will never be using it for aggregations, etc? Would doing so cause unnecessary bloat in the index? I have a lot of fields and would prefer not to have to manually edit the dynamically generated mapping if at all possible. Any guidance/thoughts that anyone may have would be appreciated. Thanks.

Kevin

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 24, 2017, 3:49pm UTC](https://discuss.elastic.co/t/question-about-dynamically-generated-keyword-fields/97815/2 "2017-08-24T15:49:03Z")

</div>

Yes, indexing strings twice (once as type text and once as type keyword) will cause more disk space to be consumed. How much more depends on your data.

If that's a concern, and you are never going to use strings for aggregating or sorting, you could use dynamic templates to map strings to text only, without having to define the type of each field explicitly. Take a look at the docs which have this exact example: [https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#\_literal\_text\_literal\_only\_mappings\_for\_strings](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#_literal_text_literal_only_mappings_for_strings)

You could use dynamic templates in combination with index templates. Then all new indexes with a name that matches the provided wildcard pattern will have your dynamic template applied to them by default: [https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html)

---

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [August 25, 2017, 5:58pm UTC](https://discuss.elastic.co/t/question-about-dynamically-generated-keyword-fields/97815/3 "2017-08-25T17:58:22Z")

</div>

@abdon Thank you very much for the info!

---

<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 22, 2017, 5:58pm UTC](https://discuss.elastic.co/t/question-about-dynamically-generated-keyword-fields/97815/4 "2017-09-22T17:58:55Z")

</div>

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