# Multi dynamic templates - issue

**URL:** <https://discuss.elastic.co/t/multi-dynamic-templates-issue/228296>\
**Category:** Elasticsearch\
**Created:** [April 16, 2020, 10:19am UTC](https://discuss.elastic.co/t/multi-dynamic-templates-issue/228296 "2020-04-16T10:19:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adude946](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@adude946](https://discuss.elastic.co/u/adude946)\
**Post date:** [April 16, 2020, 10:19am UTC](https://discuss.elastic.co/t/multi-dynamic-templates-issue/228296/1 "2020-04-16T10:19:55Z")

</div>

I'm testing implementing multiple dynamic templates on 3 different fields but each time mapping is not getting created correctly. Only the first array object template is picked up. Any help would be great on what is wrong or any alternative way to achieve this. Need different objects to have different dynamic mappings, some are root level and some are inner objects.

**Mapping:**

```
PUT /test-dy
{
  "mappings": {
    "dynamic": "strict",
    "dynamic_templates": [
      {
        "default": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword"
          }
        }
      },
      {
        "custom_field1": {
          "path_match": "fld1.*",
          "match_mapping_type": "string",
          "mapping": {
            "type": "text",
            "fields": {
              "keyword": {"type": "keyword"}
            }
          }
        }
      },
      {
        "custom_field2": {
          "path_match": "fld2.*",
          "match_mapping_type": "string",
          "mapping": {
            "type": "text"
          }
        }
      },
      {
        "custom_field3": {
          "path_match": "fld3.profile.*",
          "match_mapping_type": "string",
          "mapping": {
            "type": "text"
          }
        }
      }
    ],
    "properties": {
      "fld1": {"type": "object", "dynamic": "true"},
      "fld2": {"type": "object", "dynamic": "true"},
      "fld3": {"type": "object", "properties":{
             "name":{"type": "text"},
             "profile":{"type": "nested", "dynamic": "true"}
           }},
      "fld4": {"type": "text"}
    }
  }
}

```

**Mock data:**

```
PUT test-dy/_doc/1
{
	"fld1": {
	  "key1":"val1",
	  "key2":"val2"
	  },
	"fld2": {
	  "key1":"val1",
	  "profile":{
	    "subkey1":"val1",
	    "subkey2": ["val1"]
	  }
	  },
	"fld3": {
	  "name":"xxx",
	  "profile":[{
	    "subkey1":"val1",
	    "subkey2": ["val1"]
	  }]
	},
	"fld4":	"hello hi"
}
```

---

<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:** [May 14, 2020, 10:28am UTC](https://discuss.elastic.co/t/multi-dynamic-templates-issue/228296/2 "2020-05-14T10:28:01Z")

</div>

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