How to update the date format of an exist date field with PUT mapping API?


(Red) #1

im facing a problem that i must update the date format from "YYYY-MM-DD" to "YYYY-MM-DD HH:mm:ss",

i want to implement without reindexing.

and i found the answer in document:

The format setting must have the same setting for fields of the same name in the same index. Its value can be updated on existing fields using the PUT mapping API.

i only got error messages with the method above, here is my code:

curl -XPUT 192.168.4.216:9280/goods/_mapping/fulltext -d '
{
"fulltext":{
"properties" : {
"start_time" : { "format" : "YYYY-MM-dd HH:mm:ss" }
}
}
}
'

error message is :

{"error":"MapperParsingException[No type specified for property [start_time]]","status":400}

after i put the type into the code, ive got other error message:

{"error":"MergeMappingException[Merge failed with failures {[mapper [_all] has different index_analyzer]}]","status":400}

so how can i update the format of an exist date field without reindexing


(David Pilato) #2

If doable (I'm unsure), you must send the full mapping and not only what you want to change.

First, run a GET /index/type/_mapping
Change what you want in it
Then put the mapping.

Again, I'm unsure if you can change this setting.


(Red) #3

thank you for your help, and yes, you could be right somehow.
i add the mapping of field _all into the update body, and then it works
here is my new request

curl -XPUT 192.168.4.216:9280/test_red/_mapping/t1 -d ' { "_all":{ "auto_boost" : true, "index_analyzer" : "ik_syno" }, "properties" : { "start_time" : { "type" : "date", "format" : "YYYY-MM-dd HH:mm:ss" } } }


(system) #4