# How to range filter on floats

**URL:** <https://discuss.elastic.co/t/how-to-range-filter-on-floats/5751>\
**Category:** Elasticsearch\
**Created:** [November 2, 2011, 9:48pm UTC](https://discuss.elastic.co/t/how-to-range-filter-on-floats/5751 "2011-11-02T21:48:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kunal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kunal/32/3079_2.png) [@Kunal](https://discuss.elastic.co/u/Kunal)\
**Post date:** [November 2, 2011, 9:48pm UTC](https://discuss.elastic.co/t/how-to-range-filter-on-floats/5751/1 "2011-11-02T21:48:44Z")

</div>

Does the range filter support floats, or just integers?

If I try this, it works:

{"query":{"filtered":{"query":{"match\_all":{}},"filter":{"and":  
[{"term":{"active":1}},{"range":{"myFloatVal":{"from":1,"to":2}}}]}}}}

While with this, I get an error:

{"query":{"filtered":{"query":{"match\_all":{}},"filter":{"and":  
[{"term":{"active":1}},{"range":{"myFloatVal":{"from":1,"to":  
2.2}}}]}}}}

[2011-11-02 14:36:35,500][DEBUG][action.search.type] [Anomaly]  
[source\_6][1], node[OuGchV\_hTG6Gfk-YfLkSNA], [P], s[STARTED]: Failed  
to execute [org.elasticsearch.action.search.SearchRequest@589e5ea6]  
org.elasticsearch.search.SearchParseException: [source\_6][1]:  
from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":  
{"filtered":{"query":{"match\_all":{}},"filter":{"and":[{"term":  
{"active":1}},{"range":{"myFloatVal":{"from":1,"to":2.2}}}]}}}}]]  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
517)  
at  
org.elasticsearch.search.SearchService.createContext(SearchService.java:  
429)  
at  
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:  
232)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:  
134)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction  
$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:  
80)  
at org.elasticsearch.action.search.type.TransportSearchTypeAction  
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:205)  
at org.elasticsearch.action.search.type.TransportSearchTypeAction  
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:192)  
at org.elasticsearch.action.search.type.TransportSearchTypeAction  
$BaseAsyncAction$2.run(TransportSearchTypeAction.java:178)  
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:680)  
Caused by: java.lang.NumberFormatException: For input string: "2.2"  
at  
java.lang.NumberFormatException.forInputString(NumberFormatException.java:  
48)  
at java.lang.Long.parseLong(Long.java:419)  
at java.lang.Long.parseLong(Long.java:468)  
at  
org.elasticsearch.index.mapper.core.LongFieldMapper.rangeFilter(LongFieldMapper.java:  
172)  
at  
org.elasticsearch.index.query.NumericRangeFilterParser.parse(NumericRangeFilterParser.java:  
115)  
at  
org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:  
183)  
at  
org.elasticsearch.index.query.AndFilterParser.parse(AndFilterParser.java:  
60)  
at  
org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:  
183)  
at  
org.elasticsearch.index.query.FilteredQueryParser.parse(FilteredQueryParser.java:  
65)  
at  
org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:  
157)  
at  
org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:  
232)  
at  
org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:  
212)  
at  
org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:  
32)  
at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
505)  
... 10 more

... is there some other way I'm supposed to deal with ranges on floats?

---

<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:** [November 2, 2011, 10:15pm UTC](https://discuss.elastic.co/t/how-to-range-filter-on-floats/5751/2 "2011-11-02T22:15:47Z")

</div>

Numeric range will work on floats / doubles if the datatype you search on  
is float / double. It seems like the range filter you execute is executed  
against a "long" type field, which fails to execute it since it fails to  
parse the float number into a long.

On Wed, Nov 2, 2011 at 11:48 PM, Kunal [cvkunal@gmail.com](mailto:cvkunal@gmail.com) wrote:

> Does the range filter support floats, or just integers?
> 
> If I try this, it works:
> 
> {"query":{"filtered":{"query":{"match\_all":{}},"filter":{"and":  
> [{"term":{"active":1}},{"range":{"myFloatVal":{"from":1,"to":2}}}]}}}}
> 
> While with this, I get an error:
> 
> {"query":{"filtered":{"query":{"match\_all":{}},"filter":{"and":  
> [{"term":{"active":1}},{"range":{"myFloatVal":{"from":1,"to":  
> 2.2}}}]}}}}
> 
> [2011-11-02 14:36:35,500][DEBUG][action.search.type] [Anomaly]  
> [source\_6][1], node[OuGchV\_hTG6Gfk-YfLkSNA], [P], s[STARTED]: Failed  
> to execute [org.elasticsearch.action.search.SearchRequest@589e5ea6]  
> org.elasticsearch.search.SearchParseException: [source\_6][1]:  
> from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":  
> {"filtered":{"query":{"match\_all":{}},"filter":{"and":[{"term":  
> {"active":1}},{"range":{"myFloatVal":{"from":1,"to":2.2}}}]}}}}]]  
> at  
> org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
> 517)  
> at  
> org.elasticsearch.search.SearchService.createContext(SearchService.java:  
> 429)  
> at
> 
> org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:  
> 232)  
> at
> 
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:  
> 134)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
> 
> $AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:  
> 80)  
> at org.elasticsearch.action.search.type.TransportSearchTypeAction  
> $BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:205)  
> at org.elasticsearch.action.search.type.TransportSearchTypeAction  
> $BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:192)  
> at org.elasticsearch.action.search.type.TransportSearchTypeAction  
> $BaseAsyncAction$2.run(TransportSearchTypeAction.java:178)  
> 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:680)  
> Caused by: java.lang.NumberFormatException: For input string: "2.2"  
> at  
> java.lang.NumberFormatException.forInputString(NumberFormatException.java:  
> 48)  
> at java.lang.Long.parseLong(Long.java:419)  
> at java.lang.Long.parseLong(Long.java:468)  
> at
> 
> org.elasticsearch.index.mapper.core.LongFieldMapper.rangeFilter(LongFieldMapper.java:  
> 172)  
> at
> 
> org.elasticsearch.index.query.NumericRangeFilterParser.parse(NumericRangeFilterParser.java:  
> 115)  
> at
> 
> org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:  
> 183)  
> at  
> org.elasticsearch.index.query.AndFilterParser.parse(AndFilterParser.java:  
> 60)  
> at
> 
> org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:  
> 183)  
> at
> 
> org.elasticsearch.index.query.FilteredQueryParser.parse(FilteredQueryParser.java:  
> 65)  
> at
> 
> org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:  
> 157)  
> at
> 
> org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:  
> 232)  
> at
> 
> org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:  
> 212)  
> at
> 
> org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:  
> 32)  
> at  
> org.elasticsearch.search.SearchService.parseSource(SearchService.java:  
> 505)  
> ... 10 more
> 
> ... is there some other way I'm supposed to deal with ranges on floats?

---

<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:50am UTC](https://discuss.elastic.co/t/how-to-range-filter-on-floats/5751/3 "2017-07-06T03:50:02Z")

</div>


