# Java Client API: DateTime format for QueryBuilders/FilterBuilders

**URL:** <https://discuss.elastic.co/t/java-client-api-datetime-format-for-querybuilders-filterbuilders/22326>\
**Category:** Elasticsearch\
**Created:** [February 23, 2015, 11:47am UTC](https://discuss.elastic.co/t/java-client-api-datetime-format-for-querybuilders-filterbuilders/22326 "2015-02-23T11:47:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_P](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@Simon\_P](https://discuss.elastic.co/u/Simon_P)\
**Post date:** [February 23, 2015, 11:47am UTC](https://discuss.elastic.co/t/java-client-api-datetime-format-for-querybuilders-filterbuilders/22326/1 "2015-02-23T11:47:16Z")

</div>

I'm stuck with a DateTime formatter problem.

QueryBuilders.constantScoreQuery(FilterBuilders.rangeFilter("lastSeen").lte(  
DateTime.now(DateTimeZone.UTC)));

According to my doc type mapping, the field "lastSeen" is of type "date"  
with format "date\_time\_no\_millis". Executing the defined query will leave  
me with a parse failure, because the Joda DateTime object was serialized in  
an unexpected format.

Parse Failure [Failed to parse source [{"from":0,"size":0,"query":{  
"constant\_score":{"filter":{"range":{"lastSeen":{"from":null,"to":  
"2015-02-23T11:18:28.121Z","include\_lower":true,"include\_upper":true}}}}}}]]  
org.elasticsearch.ElasticsearchParseException: failed to parse date field [  
2015-02-23T11:18:28.121Z], tried both date format [date\_time\_no\_millis], and  
timestamp number

Well the format is not really unexpected, it's the default format the  
XContentBuilder is using, but it's still not the format the server is  
expecting, according to the mapping.

public final static DateTimeFormatter defaultDatePrinter = ISODateTimeFormat  
.dateTime().withZone(DateTimeZone.UTC);

The question now is, is there a way to overwrite the default formatter and  
define the format it should use or maybe a setting to make the client aware  
of the doc type mapping?  
The only solution I found so far is serializing in the correct format on my  
own and passing a String instead of a DateTime object. But I figure there  
must be a better solution.

I'm on ElasticSearch 1.3.7.

Thanks  
Simon

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ae763740-5ca1-46b6-b09a-c93dbde28427%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ae763740-5ca1-46b6-b09a-c93dbde28427%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:30am UTC](https://discuss.elastic.co/t/java-client-api-datetime-format-for-querybuilders-filterbuilders/22326/2 "2017-07-06T00:30:49Z")

</div>


