# Date type mapping and its values

**URL:** <https://discuss.elastic.co/t/date-type-mapping-and-its-values/26843>\
**Category:** Elasticsearch\
**Created:** [August 5, 2015, 3:50am UTC](https://discuss.elastic.co/t/date-type-mapping-and-its-values/26843 "2015-08-05T03:50:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [August 5, 2015, 3:50am UTC](https://discuss.elastic.co/t/date-type-mapping-and-its-values/26843/1 "2015-08-05T03:50:11Z")

</div>

hi,  
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.  
e.g.  
field\_x : 1438396514958  
field\_y : 2015-08-01T00:35:25.000Z

what could be the reason for this?

thanks

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [August 5, 2015, 5:45am UTC](https://discuss.elastic.co/t/date-type-mapping-and-its-values/26843/2 "2015-08-05T05:45:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:57pm UTC](https://discuss.elastic.co/t/date-type-mapping-and-its-values/26843/3 "2017-07-05T23:57:22Z")

</div>


