Mapping problem with dynamic_date_formats (ES 2.0)


(Lar Mader) #1

ElasticSearch 2.0:

I am using "dynamic_date_formats" with the default type to apply date detection across all types. I have a date field with the same name that exists in multiple types.

When the first document (of a given type) with my date field is encountered, it correctly detects the date, creates the mapping for this type, and formats the date field correctly. However, when another document of a different type (that has the same date field name) is indexed, it complains that:

Mapper for [myDate] conflicts with existing mapping in other types:
[mapper [myDate] is used by multiple types. Set update_all_types to true to update [format] across all types.]

Since the mapping is the same, as defined by the "dynamic_date_formats" configuration, why does this not work?

Here is a stripped down sequence of curl commands that repro's my problem (note that the documents are type1 and type2):

$ curl -XPUT http://localhost:9200/myIndex -d '{"mappings": {"_default_": 
    { "dynamic_date_formats": ["yyyy-MM-dd"]}
}}'

$ curl -XPOST http://localhost:9200/myIndex/type1 -d '{"myDate":"2015-01-01"}'

$ curl -XPOST http://localhost:9200/myIndex/type2 -d '{"myDate":"2015-01-02"}'

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Mapper for [myDate] conflicts with existing mapping in other types:\n[mapper [myDate] is used by multiple types. Set update_all_types to true to update [format] across all types.]"}],"type":"illegal_argument_exception","reason":"Mapper for [myDate] conflicts with existing mapping in other types:\n[mapper [myDate] is used by multiple types. Set update_all_types to true to update [format] across all types.]"},"status":400}

Any ideas?


(Colin Goodheart-Smithe) #2

@larmader This seems to be a bug. I have raised an issue for this here: https://github.com/elastic/elasticsearch/issues/15138

Thanks for bringing this to our attention. Until this bug is fixed there is a work around. Replace your index creation request with the following:

PUT /my_index
{
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "date_fields": {
            "match_mapping_type": "date",
            "mapping": {
              "type": "date",
              "format": "yyyy-MM-dd"
            }
          }
        }
      ]
    }
  }
}

Hope that helps


(Lar Mader) #3

Awesome, this work around appears to working correctly. Thank you!


(system) #4