How to range filter on floats


(Kunal) #1

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?


(Shay Banon) #2

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 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?


(system) #3