# Mappings.\_default\_.dynamic\_templates doesn't show up in resulting mapping

**URL:** https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030
**Category:** Elasticsearch
**Created:** [August 26, 2016, 11:12am UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030 "2016-08-26T11:12:12Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Carsten\_Germer](https://avatars.discourse-cdn.com/v4/letter/c/ed655f/32.png) [@Carsten\_Germer](https://discuss.elastic.co/u/Carsten_Germer)
#### Post date: [August 26, 2016, 11:12am UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/1 "2016-08-26T11:12:12Z")

</div>

Hi everyone,

Using ES 2.3 I create an index with default dynamic templates, just like in the examples.

```
PUT /myindex
{
    "mappings": { 
        "_default_": {
            "dynamic_templates": [
                {
                    "no_date_detection": {
                        "match_mapping_type": "string",
                        "mapping": {
                            "type": "string",
                            "date_detection": false
                       }
                    }
                }
            ]
        }
    }
}

```

Then I create a new type and object by

```
PUT /myindex/gardeners/1
{
    "name": "Oscar"
}

```

When I GET the \_mapping afterwards it shows that the default mapping is handed down to the type "gardeners" but `"date_detection": false` does not show up in the mapping of the new field "name".

```
{
   "myindex": {
      "mappings": {
         "_default_": {
            "dynamic_templates": [
               {
                  "no_date_detection": {
                     "mapping": {
                        "type": "string",
                        "date_detection": false
                     },
                     "match_mapping_type": "string"
                  }
               }
            ]
         },
         "gardeners": {
            "dynamic_templates": [
               {
                  "no_date_detection": {
                     "mapping": {
                        "type": "string",
                        "date_detection": false
                     },
                     "match_mapping_type": "string"
                  }
               }
            ],
            "properties": {
               "name": {
                  "type": "string"
               }
            }
         }
      }
   }
}

```

Shouldn't the properties for the field "name" be

```
        "properties": {
           "name": {
              "type": "string",
              "date_detection": false
           }
        }

```

?

Is this expected behaviour? And if, how can I verify the mapping got applied to the field?

Thanks in advance and cheers /Carsten

Edit: Fixed preformatted

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [August 26, 2016, 11:38am UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/2 "2016-08-26T11:38:37Z")

</div>

yes, this is expected behavior. Once the String type is determined for the `name` field, there is no need for `date_detection` on that level. The `date_detection` is only relevant when ES encounters a new String field (see [here](https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html#date-detection)).

If you want to test that the templates get properly applied to the field, try indexing a new document with a different field where you put a date as string value.

---

<div class="post-metadata">

### Author: ![Carsten\_Germer](https://avatars.discourse-cdn.com/v4/letter/c/ed655f/32.png) [@Carsten\_Germer](https://discuss.elastic.co/u/Carsten_Germer)
#### Post date: [August 26, 2016, 12:09pm UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/3 "2016-08-26T12:09:12Z")

</div>

Understood. But when, after deleting the index and creating it again, I put in

```
PUT /myindex/gardeners/1
{
    "name": "2009-11-15T14:12:12"
}

```

GET \_mapping shows

```
        "properties": {
           "name": {
              "type": "date",
              "format": "strict_date_optional_time||epoch_millis"
           }
        }

```

So, the dynamic template didn't get applied. I can't find the error in that minimalistic code I more or less copied from the documentation. I think I remember that, when I first tried ES, it actually did work.

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [August 26, 2016, 12:38pm UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/4 "2016-08-26T12:38:48Z")

</div>

ok, I think that dynamic\_templates don't allow you to specify the `date_detection`.  
You have to specify the `date_detection` directly on the mapping (not at the level of a specific type), i.e. do

```auto
PUT /myindex
{
    "mappings": {
        "gardeners": {
            "date_detection": false
        }
    }
}

```

before indexing the first document.

If you want this to get automatically added to new indices, you can use index templates.

---

<div class="post-metadata">

### Author: ![Carsten\_Germer](https://avatars.discourse-cdn.com/v4/letter/c/ed655f/32.png) [@Carsten\_Germer](https://discuss.elastic.co/u/Carsten_Germer)
#### Post date: [August 26, 2016, 12:56pm UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/5 "2016-08-26T12:56:48Z")

</div>

Thanks Yannick, that is the case.  
Now that I know what I'm looking for I also find that in the documentation [https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html)  
Well, I'll be off checking and fixing like 20 models 😉

Looks like

```
PUT /myindex
{
    "mappings": { 
        "_default_": {
          "date_detection": false
        }
    }
}

```

achieves what I need.

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [August 27, 2016, 1:58pm UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/6 "2016-08-27T13:58:33Z")

</div>

> [@Carsten\_Germer](#):
>
> ```auto
> PUT /myindex
> {
> "mappings": { 
> "_default_": {
> "dynamic_templates": [
> {
> "no_date_detection": {
> "match_mapping_type": "string",
> "mapping": {
> "type": "string",
> "date_detection": false
> }
> }
> }
> ]
> }
> }
> }
> 
> ```

Just one thing I wanted to add here for sake of completeness: In ES v5.0.0, we are throwing an exception that `date_detection` is an invalid parameter in that place.

---

<div class="post-metadata">

### Author: ![iamredlus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iamredlus/32/15504_2.png) [@iamredlus](https://discuss.elastic.co/u/iamredlus)
#### Post date: [February 14, 2017, 3:49pm UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/7 "2017-02-14T15:49:30Z")

</div>

Hey everyone,

On the same subject - do you know if it is possible to mix date\_detection true and false within the same mapping?

i.e. something similar to this:

> ```
> PUT /myindex
> {
> "mappings": { 
> "_default_": {
> "dynamic": true,
> "date_detection": false,
> "dynamic_templates": [
> {
> "date_detection_off": {
> "match": "*_nodate",
> "match_mapping_type": "string",
> "mapping": {
> "type": "string",
> }
> }
> },
> {
> "date_detection_on": {
> "match": "*_yesdate",
> "match_mapping_type": "string",
> "mapping": {
> "type": "dateOptionalTime",
> "date_detection": true
> }
> }
> }
> ]
> }
> }
> }
> 
> ```

Thanks  
Lior

---

<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 5, 2017, 10:03pm UTC](https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030/8 "2017-07-05T22:03:15Z")

</div>


