# Create new index with dynamic mapping for dates

**URL:** <https://discuss.elastic.co/t/create-new-index-with-dynamic-mapping-for-dates/166098>\
**Category:** Elasticsearch\
**Created:** [January 29, 2019, 6:39am UTC](https://discuss.elastic.co/t/create-new-index-with-dynamic-mapping-for-dates/166098 "2019-01-29T06:39:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ottadini](https://avatars.discourse-cdn.com/v4/letter/o/b19c9b/32.png) [@ottadini](https://discuss.elastic.co/u/ottadini)\
**Post date:** [January 29, 2019, 6:39am UTC](https://discuss.elastic.co/t/create-new-index-with-dynamic-mapping-for-dates/166098/1 "2019-01-29T06:39:25Z")

</div>

I want my indices to recognise a few different date formats. Some of these formats look like this:  
29.06.06 (so a date format of "dd.MM.yy"?)  
29-06-06  
29/Jun/2006.

From what I've read, I _think_ I need to create a dynamic mapping like this:

```
put $indexname/_mapping/_default_
{
    "date_detection": true,
    "dynamic_templates": [
        {
        "dates": {
            "match": ".*date.*|.*DATE.*|.*Date.*",
            "match_pattern": "regex",
            "mapping": {
            "type": "date",
            "format": "dd.MM.yy||dd-MM-yy||dd/MM/yyyy||strict_date_optional_time||dateOptionalTime"
            }
        }
    }]
}

```

How can I do this on index creation?

---

<div class="post-metadata">

**Author:** ![ottadini](https://avatars.discourse-cdn.com/v4/letter/o/b19c9b/32.png) [@ottadini](https://discuss.elastic.co/u/ottadini)\
**Post date:** [February 1, 2019, 1:30am UTC](https://discuss.elastic.co/t/create-new-index-with-dynamic-mapping-for-dates/166098/2 "2019-02-01T01:30:05Z")

</div>

Just in case someone else comes here with a similar question, I decided to not use a dynamic template, but instead to alter the `dynamic_date_formats` in an index template, which I think works well enough for me.

```
PUT _template/test_index_template
{
    "index_patterns": "test*",
    "version": 101,
    "mappings": {
        "_doc": {
            "dynamic_date_formats": [
                "dd.MM.yy",
                "dd.MMM.yy",
                "dd.MM.yyyy",
                "dd.MMM.yyyy"
            ],
            "date_detection": true
        }
    }
}
```

---

<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:** [March 1, 2019, 1:30am UTC](https://discuss.elastic.co/t/create-new-index-with-dynamic-mapping-for-dates/166098/3 "2019-03-01T01:30:08Z")

</div>

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