Skip to content

dynamic_date_formats ignored if dynamic_templates for date is present #9410

Closed
@SergeyTsalkov

Description

@SergeyTsalkov

My goal was to have a dynamically created date field with the ignore_malformed option set. However, when I have both dynamic_date_formats and dynamic_templates for the date type, the dynamic_date_formats is ignored.

So let's create our index..

curl -XPOST localhost:9200/test -d '{
  "mappings": {
    "test": {
      "dynamic_date_formats": [
        "yyyy-MM-dd"
      ],
      "dynamic_templates": [
        {
          "dates_ignore_malformed": {
            "path_match": "*",
            "match_mapping_type": "date",
            "mapping": {
              "ignore_malformed": true
            }
          }
        }
      ]
    }
  }
}'

And add some data..

curl -XPOST localhost:9200/test/test/1 -d '{
  "something": "2014-01-05"
}'

And now get the mappings back..

curl -XGET localhost:9200/test/_mappings
->
{
  "test": {
    "mappings": {
      "test": {
        "dynamic_date_formats": [
          "yyyy-MM-dd"
        ],
        "dynamic_templates": [
          {
            "dates_ignore_malformed": {
              "mapping": {
                "ignore_malformed": true
              },
              "match_mapping_type": "date",
              "path_match": "*"
            }
          }
        ],
        "properties": {
          "something": {
            "type": "date",
            "ignore_malformed": true,
            "format": "dateOptionalTime"
          }
        }
      }
    }
  }
}

See how the format for "something" is dateOptionalTime? Had I not included the dynamic_templates, that would have been (and should have been) "yyyy-MM-dd".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions