Elasticsearch: Strict_Dynamic_Mapping_Exception

Elasticsearch: Strict_Dynamic_Mapping_Exception

Hi, I am trying to modify the date format in an elasticsearch index (operate-operation-0.26.0_). But I get the following error.

{
  "took" : 148,
  "errors" : true,
  "items" : [
    {
      "index" : {
        "_index" : "operate-operation-0.26.0_",
        "_type" : "_doc",
        "_id" : "WBGhSXcB_hD8-yfn-Rh5",
        "status" : 400,
        "error" : {
          "type" : "strict_dynamic_mapping_exception",
          "reason" : "mapping set to strict, dynamic introduction of [dynamic] within [_doc] is not allowed"
        }
      }
    }
  ]
}

The json file I am using is bulk6.json:

{"index":{}}

{"dynamic":"strict","properties":{"date":{"type":"date","format":"yyyy-MM-dd'T'HH:mm:ss.SSSZZ"}}}

The command I am running is

curl -H "Content-Type: application/x-ndjson" -XPOST 'localhost:9200/operate-operation-0.26.0_/_bulk?pretty&refresh' --data-binary @"bulk6.json"

1 Answer

The _bulk API endpoint is not meant for changing mappings. You need to use the _mapping API endpoint like this:

The JSON file mapping.json should contain:

{
  "dynamic": "strict",
  "properties": {
    "date": {
      "type": "date",
      "format": "yyyy-MM-dd'T'HH:mm:ss.SSSZZ"
    }
  }
}

And then the call can be made like this:

curl -H "Content-Type: application/json" -XPUT 'localhost:9200/operate-operation-0.26.0_/_mapping?pretty&refresh' --data-binary @"mapping.json"

However, this is still not going to work as you're not allowed to change the date format after the index has been created. You're going to get the following error:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Mapper for [date] conflicts with existing mapper:\n\tCannot update parameter [format] from [strict_date_optional_time||epoch_millis] to [yyyy-MM-dd'T'HH:mm:ss.SSSZZ]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "Mapper for [date] conflicts with existing mapper:\n\tCannot update parameter [format] from [strict_date_optional_time||epoch_millis] to [yyyy-MM-dd'T'HH:mm:ss.SSSZZ]"
  },
  "status" : 400
}

You need to create a new index with the desired correct mapping and reindex your data.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.