Date type mapping and its values

(T Vinod Gupta) #1

we have an index with static mappings and there are 2 fields with the same type -
field_x : {
"type" : "date",
"format" : "dateOptionalTime"
similarly, another field is called field_y with the same type and format.

the documents are created using java api and fields are set using Date objects. but what is strange is that the json output from GET command shows the values in different format.
field_x : 1438396514958
field_y : 2015-08-01T00:35:25.000Z

what could be the reason for this?


(Andrei Stefan) #2

That is like that because you see the _source, meaning the way the field value has been indexed. For example, if you indexed:

POST /test/test/1
{"field_x": "1438396514958"}
POST /test/test/2
{"field_y": "2015-08-01T00:35:25.000Z"}

Doing GET /test/test/_search it will get back the values you indexed, no matter what format the fields have in the mapping. You could use script_fields and a Groovy script to have that date visually formatted the way you want it.

(system) #3