# Mapped date field returned as string?

**URL:** <https://discuss.elastic.co/t/mapped-date-field-returned-as-string/4223>\
**Category:** Elasticsearch\
**Created:** [April 12, 2011, 7:52pm UTC](https://discuss.elastic.co/t/mapped-date-field-returned-as-string/4223 "2011-04-12T19:52:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacorob](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jacorob](https://discuss.elastic.co/u/jacorob)\
**Post date:** [April 12, 2011, 7:52pm UTC](https://discuss.elastic.co/t/mapped-date-field-returned-as-string/4223/1 "2011-04-12T19:52:02Z")

</div>

Are date mapped fields not converted to java.lang.Date objects?

I search for a document that has one field mapped to a date  
"properties" : {  
"\_value" : {  
"format" : "dateOptionalTime",  
"type" : "date"  
},

When I look at the source of the document that was returned as a  
search hit the object type of the field value is a java.lang.String  
instead of a java.lang.Date. I guess I was expecting date fields to be  
converted to java.util.Date. The integers, booleans, etc appear to be  
returned as the appropriate java objects (Integer, Boolean, etc). An  
example string returned for a "date" mapped field was  
"2011-04-12T19:18:41.172Z". Is this expected? Is it not converted to a  
Date since the mapping specifies the format? Is there a way for it to  
return a date object (e.g. - if i specify a specific format)? Just  
hoping to avoid having to store meta data in the source to track date  
fields (so I know to load to a Date object) since my mapping already  
does that.

Thanks,  
Bob

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 12, 2011, 8:19pm UTC](https://discuss.elastic.co/t/mapped-date-field-returned-as-string/4223/2 "2011-04-12T20:19:55Z")

</div>

Heya,

No, they are not converted to Dates, though its quite simple to convert it yourself (and use Joda, not the horror that is java.util.Date and friends). The reason for that is that it follows more closely the json data model. In general, it could have been done.

-shay.banon  
On Tuesday, April 12, 2011 at 10:52 PM, Bob wrote:

> Are date mapped fields not converted to java.lang.Date objects?
> 
> I search for a document that has one field mapped to a date  
> "properties" : {  
> "\_value" : {  
> "format" : "dateOptionalTime",  
> "type" : "date"  
> },
> 
> When I look at the source of the document that was returned as a  
> search hit the object type of the field value is a java.lang.String  
> instead of a java.lang.Date. I guess I was expecting date fields to be  
> converted to java.util.Date. The integers, booleans, etc appear to be  
> returned as the appropriate java objects (Integer, Boolean, etc). An  
> example string returned for a "date" mapped field was  
> "2011-04-12T19:18:41.172Z". Is this expected? Is it not converted to a  
> Date since the mapping specifies the format? Is there a way for it to  
> return a date object (e.g. - if i specify a specific format)? Just  
> hoping to avoid having to store meta data in the source to track date  
> fields (so I know to load to a Date object) since my mapping already  
> does that.
> 
> Thanks,  
> Bob

---

<div class="post-metadata">

**Author:** ![jacorob](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jacorob](https://discuss.elastic.co/u/jacorob)\
**Post date:** [April 12, 2011, 8:41pm UTC](https://discuss.elastic.co/t/mapped-date-field-returned-as-string/4223/3 "2011-04-12T20:41:55Z")

</div>

Thanks, Shay. I just included some meta data to mark that the String  
is really a date, and used joda time to convert it to a date object.  
Easy sneezy.

Thanks,  
Bob

On Apr 12, 3:19 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Heya,
> 
> No, they are not converted to Dates, though its quite simple to convert it yourself (and use Joda, not the horror that is java.util.Date and friends). The reason for that is that it follows more closely the json data model. In general, it could have been done.
> 
> -shay.banon
> 
> On Tuesday, April 12, 2011 at 10:52 PM, Bob wrote:
> 
> > Are date mapped fields not converted to java.lang.Date objects?
> 
> > I search for a document that has one field mapped to a date  
> > "properties" : {  
> > "\_value" : {  
> > "format" : "dateOptionalTime",  
> > "type" : "date"  
> > },
> 
> > When I look at the source of the document that was returned as a  
> > search hit the object type of the field value is a java.lang.String  
> > instead of a java.lang.Date. I guess I was expecting date fields to be  
> > converted to java.util.Date. The integers, booleans, etc appear to be  
> > returned as the appropriate java objects (Integer, Boolean, etc). An  
> > example string returned for a "date" mapped field was  
> > "2011-04-12T19:18:41.172Z". Is this expected? Is it not converted to a  
> > Date since the mapping specifies the format? Is there a way for it to  
> > return a date object (e.g. - if i specify a specific format)? Just  
> > hoping to avoid having to store meta data in the source to track date  
> > fields (so I know to load to a Date object) since my mapping already  
> > does that.
> 
> > Thanks,  
> > Bob

---

<div class="post-metadata">

**Author:** ![elmaghraoui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elmaghraoui/32/59150_2.png) [@elmaghraoui](https://discuss.elastic.co/u/elmaghraoui)\
**Post date:** [May 9, 2014, 1:51pm UTC](https://discuss.elastic.co/t/mapped-date-field-returned-as-string/4223/4 "2014-05-09T13:51:46Z")

</div>

would you mind to post the code of your solution

---

<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 6, 2017, 1:30am UTC](https://discuss.elastic.co/t/mapped-date-field-returned-as-string/4223/5 "2017-07-06T01:30:31Z")

</div>


