Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

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"
question from:https://stackoverflow.com/questions/65940600/elasticsearch-strict-dynamic-mapping-exception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:
Cannot 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:
Cannot 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...