# Including dynamic templates for the elastic index

**URL:** https://discuss.elastic.co/t/including-dynamic-templates-for-the-elastic-index/257784
**Category:** Elasticsearch
**Created:** [December 6, 2020, 7:31pm UTC](https://discuss.elastic.co/t/including-dynamic-templates-for-the-elastic-index/257784 "2020-12-06T19:31:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![radhika](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@radhika](https://discuss.elastic.co/u/radhika)
#### Post date: [December 6, 2020, 7:31pm UTC](https://discuss.elastic.co/t/including-dynamic-templates-for-the-elastic-index/257784/1 "2020-12-06T19:31:15Z")

</div>

Hello everyone,

I have an elastic index with the mappings set to strict except for one field which is dynamic. I would also like to set the mapping of the dynamic field using dynamic templates

```auto
PUT trial
{
   "mappings": {
      "dynamic": "strict",
      "properties": {
         "field1": {
            "type": "nested",
            "properties": {
               "display": {
                  "type": "keyword",
                  "index": "true"
               }
            }
         },
         "customFields": {
            "dynamic": true,
            "properties": {}
         }
      },
      "dynamic_templates": [
         {
            "customFields": {
               "match": "customFields",
               "mapping": {
                  "type": "text",
                  "index": "true"
               }
            }
         }
      ]
   }
}

```

Once I try to index the data in this index, it looks like the dynamic template is not applied

```auto
 "customFields": { - 
          "dynamic": "true",
          "properties": { - 
            "countries": { - 
              "type": "text",
              "fields": { - 
                "keyword": { - 
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            } 
         }
       }

```

I am missing something in here, but cannot find out what. Many thanks!

---

<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: [December 7, 2020, 2:10am UTC](https://discuss.elastic.co/t/including-dynamic-templates-for-the-elastic-index/257784/2 "2020-12-07T02:10:29Z")

</div>

You cannot mix strict and dynamic like that sorry to say.

---

<div class="post-metadata">

### Author: ![radhika](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@radhika](https://discuss.elastic.co/u/radhika)
#### Post date: [December 7, 2020, 11:45am UTC](https://discuss.elastic.co/t/including-dynamic-templates-for-the-elastic-index/257784/3 "2020-12-07T11:45:04Z")

</div>

Thanks @warkolm for your inputs. So I guess the only way is to use the default mapping for dynamic field, i.e, allow the customFields to be indexed as both text and keyword.

---

<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: [December 7, 2020, 8:03pm UTC](https://discuss.elastic.co/t/including-dynamic-templates-for-the-elastic-index/257784/4 "2020-12-07T20:03:42Z")

</div>

Yep.

---

<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: [January 4, 2021, 8:03pm UTC](https://discuss.elastic.co/t/including-dynamic-templates-for-the-elastic-index/257784/5 "2021-01-04T20:03:47Z")

</div>

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