Create new index with dynamic mapping for dates

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?

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
        }
    }
}

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