Update format for an existing field of date type

I currently use ElasticSearch 7.2.0.

I followed the instructions here to update the format of an existing field of date type:

{
  "mappings": {
    "properties": {
      "TimeStamp": {
        "type":   "date",
        "format": "yyyy-MM-ddTHH:mm:ssZ"
      }
    }
  }
}

However, I received this error:

{
    "error": {
        "root_cause": [
            {
                "type": "resource_already_exists_exception",
                "reason": "index [gaze/Po9kUGesSWCzfEME1sZ3Sg] already exists",
                "index_uuid": "Po9kUGesSWCzfEME1sZ3Sg",
                "index": "gaze"
            }
        ],
        "type": "resource_already_exists_exception",
        "reason": "index [gaze/Po9kUGesSWCzfEME1sZ3Sg] already exists",
        "index_uuid": "Po9kUGesSWCzfEME1sZ3Sg",
        "index": "gaze"
    },
    "status": 400
}

Short of creating a new index with the desired mapping and then transferring all the data from the old index to the new one, how can I update the date format of an existing field?

You can not update an existing field.
You can create a new field with the settings you want to use though.

If you need to update an existing field, you need to create a new index with the mapping you want to have and reindex all your data. The reindex API might help.

Thanks for your reply. I tried re-indexing, but received many errors with similar messages:

{
	"index": "gaze_new",
	"type": "_doc",
	"id": "fVj-8WwBPESVc1yT9rFL",
	"cause": {
		"type": "mapper_parsing_exception",
		"reason": "failed to parse field [Timestamp] of type [date] in document with id 'fVj-8WwBPESVc1yT9rFL'",
		"caused_by": {
			"type": "illegal_argument_exception",
			"reason": "failed to parse date field [2019-09-02T14:18:35.1714475 02:00] with format [yyyy-MM-dd'T'HH:mm:ssZ]",
			"caused_by": {
				"type": "date_time_parse_exception",
				"reason": "Text '2019-09-02T14:18:35.1714475 02:00' could not be parsed at index 19"
			}
		}
	},
	"status": 400
}

Is this even possible to fix?

You defined yyyy-MM-dd'T'HH:mm:ssZ as the format but you sent 2019-09-02T14:18:35.1714475 02:00 which has .1714475 in addition.

I'm not expert in time format, but you need to find the right one from this page I guess. I'm not sure if we can parse nanoseconds with the standard date field type. You probably need to use https://www.elastic.co/guide/en/elasticsearch/reference/current/date_nanos.html in that case.

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