# Problem with RangeFilter on Date field

**URL:** https://discuss.elastic.co/t/problem-with-rangefilter-on-date-field/7447
**Category:** Elasticsearch
**Created:** [April 24, 2012, 8:14am UTC](https://discuss.elastic.co/t/problem-with-rangefilter-on-date-field/7447 "2012-04-24T08:14:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Wojciech\_Durczynski](https://avatars.discourse-cdn.com/v4/letter/w/fbc32d/32.png) [@Wojciech\_Durczynski](https://discuss.elastic.co/u/Wojciech_Durczynski)
#### Post date: [April 24, 2012, 8:14am UTC](https://discuss.elastic.co/t/problem-with-rangefilter-on-date-field/7447/1 "2012-04-24T08:14:47Z")

</div>

Hello. I have a date field in my documents. Its mapping is:

{  
"type" : "date",  
"format" : "basic\_date\_time"  
}

I'd like to filter my documents by this date field.

I create filter like this:

val minValue = new org.joda.time.DateTime().minusHours(1)

val maxValue = new org.joda.time.DateTime()

val filter = FilterBuilders.rangeFilter("fieldpath").from(minValue).to(maxValue)

And when executing query with this filter there is an exception:

at org.elasticsearch.search.SearchService.parseSource(SearchService.java:557)  
at org.elasticsearch.search.SearchService.createContext(SearchService.java:469)  
at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:301)  
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:560)  
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:549)  
at org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.run(MessageChannelHandler.java:374)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)  
Caused by: org.elasticsearch.ElasticSearchParseException: failed to parse date field [2012-04-24T09:03:10.636+02:00], tried both date format [basic\_date\_time], and timestamp number  
at org.elasticsearch.common.joda.DateMathParser.parseStringValue(DateMathParser.java:194)  
at org.elasticsearch.common.joda.DateMathParser.parse(DateMathParser.java:49)  
at org.elasticsearch.common.joda.DateMathParser.parse(DateMathParser.java:23)  
at org.elasticsearch.index.mapper.core.DateFieldMapper.rangeFilter(DateFieldMapper.java:262)  
at org.elasticsearch.index.query.RangeFilterParser.parse(RangeFilterParser.java:119)  
at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:224)  
at org.elasticsearch.index.query.AndFilterParser.parse(AndFilterParser.java:72)  
at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:224)  
at org.elasticsearch.index.query.FilteredQueryParser.parse(FilteredQueryParser.java:68)  
at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:192)  
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:243)  
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:223)  
at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)  
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:545)  
... 8 more  
Caused by: java.lang.IllegalArgumentException: Invalid format: "2012-04-24T09:03:10.636+02:00" is malformed at "-04-24T09:03:10.636+02:00"  
at org.elasticsearch.common.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:644)  
at org.elasticsearch.common.joda.DateMathParser.parseStringValue(DateMathParser.java:188)  
... 21 more

I use Elastic Search 0.19.1.

When changing filter to FilterBuilders.rangeFilter("fieldpath").from(minValue.getMillis()).to(maxValue.getMillis()) it works ok.

Is it a bug?

Regards

Wojciech Durczyński

---

<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 25, 2012, 4:04pm UTC](https://discuss.elastic.co/t/problem-with-rangefilter-on-date-field/7447/2 "2012-04-25T16:04:08Z")

</div>

By default when you provide Joda date time, it will use the default ISO one  
to serialize it. Maybe convert it to basicDateTime yourself and provide the  
string value, or get the millis from it and provide it as the from/to.

2012/4/24 Wojciech Durczyński [wojciech.durczynski@comarch.com](mailto:wojciech.durczynski@comarch.com)

> Hello. I have a date field in my documents. Its mapping is:
> 
> {  
> "type" : "date",  
> "format" : "basic\_date\_time"  
> }
> 
> I'd like to filter my documents by this date field.
> 
> I create filter like this:
> 
> val minValue = new org.joda.time.DateTime().minusHours(1)
> 
> val maxValue = new org.joda.time.DateTime()
> 
> val filter = FilterBuilders.rangeFilter("fieldpath").from(minValue).to(maxValue)
> 
> And when executing query with this filter there is an exception:
> 
> at org.elasticsearch.search.SearchService.parseSource(SearchService.java:557)  
> at org.elasticsearch.search.SearchService.createContext(SearchService.java:469)  
> at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:301)  
> at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:560)  
> at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:549)  
> at org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.run(MessageChannelHandler.java:374)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:662)  
> Caused by: org.elasticsearch.ElasticSearchParseException: failed to parse date field [2012-04-24T09:03:10.636+02:00], tried both date format [basic\_date\_time], and timestamp number  
> at org.elasticsearch.common.joda.DateMathParser.parseStringValue(DateMathParser.java:194)  
> at org.elasticsearch.common.joda.DateMathParser.parse(DateMathParser.java:49)  
> at org.elasticsearch.common.joda.DateMathParser.parse(DateMathParser.java:23)  
> at org.elasticsearch.index.mapper.core.DateFieldMapper.rangeFilter(DateFieldMapper.java:262)  
> at org.elasticsearch.index.query.RangeFilterParser.parse(RangeFilterParser.java:119)  
> at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:224)  
> at org.elasticsearch.index.query.AndFilterParser.parse(AndFilterParser.java:72)  
> at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:224)  
> at org.elasticsearch.index.query.FilteredQueryParser.parse(FilteredQueryParser.java:68)  
> at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:192)  
> at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:243)  
> at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:223)  
> at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)  
> at org.elasticsearch.search.SearchService.parseSource(SearchService.java:545)  
> ... 8 more  
> Caused by: java.lang.IllegalArgumentException: Invalid format: "2012-04-24T09:03:10.636+02:00" is malformed at "-04-24T09:03:10.636+02:00"  
> at org.elasticsearch.common.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:644)  
> at org.elasticsearch.common.joda.DateMathParser.parseStringValue(DateMathParser.java:188)  
> ... 21 more
> 
> I use Elastic Search 0.19.1.
> 
> When changing filter to FilterBuilders.rangeFilter("fieldpath").from(minValue.getMillis()).to(maxValue.getMillis()) it works ok.
> 
> Is it a bug?
> 
> Regards
> 
> Wojciech Durczyński

---

<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, 3:31am UTC](https://discuss.elastic.co/t/problem-with-rangefilter-on-date-field/7447/3 "2017-07-06T03:31:05Z")

</div>


