Skip to content

Fix term(s) query for range field#25918

Merged
jpountz merged 2 commits intoelastic:masterfrom
scincowork:fixTermQueryForRanges
Jul 31, 2017
Merged

Fix term(s) query for range field#25918
jpountz merged 2 commits intoelastic:masterfrom
scincowork:fixTermQueryForRanges

Conversation

@scincowork
Copy link
Copy Markdown

No longer able to run a term(s) query on a long_range field from v5.5.0 and later.

Example query:

{
    "query": {
        "bool": {
            "filter": {
                "terms": {
                    "iprange": [1593315665,1595584936,1184220823,1187276336]
                }
            }
        }
    }
}

The following error message is produced: java.lang.IllegalArgumentException: Field [iprange] of type [long_range] does not support range queries

This occurs after the removal of the rangeQuery definition in RangeFieldMapper.java (see commit) between v5.4.0 and v5.5.0. This caused the call to rangeQuery inside termQuery to resort to the rangeQuery in MappedFieldType.java, where the exception is thrown.

I've modified the call to rangeQuery in termQuery to do what it had been doing before the 5-length argument definition was removed: pass in ShapeRelation.INTERSECTS before context.

Example error message:

        at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:329) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:312) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.parseSource(SearchService.java:613) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.createContext(SearchService.java:481) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:457) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:253) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:330) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:327) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.transport.TcpTransport$RequestHandler.doRun(TcpTransport.java:1544) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.5.0.jar:5.5.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[?:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[?:1.8.0_121]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_121]
Caused by: java.lang.IllegalArgumentException: Field [iprange] of type [long_range] does not support range queries
        at org.elasticsearch.index.mapper.MappedFieldType.rangeQuery(MappedFieldType.java:354) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.mapper.RangeFieldMapper$RangeFieldType.termQuery(RangeFieldMapper.java:278) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.mapper.MappedFieldType.termsQuery(MappedFieldType.java:348) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.TermsQueryBuilder.handleTermsQuery(TermsQueryBuilder.java:438) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.TermsQueryBuilder.doToQuery(TermsQueryBuilder.java:411) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:96) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.AbstractQueryBuilder.toFilter(AbstractQueryBuilder.java:118) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.BoolQueryBuilder.addBooleanClauses(BoolQueryBuilder.java:446) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.BoolQueryBuilder.doToQuery(BoolQueryBuilder.java:419) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:96) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$1(QueryShardContext.java:313) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:325) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:312) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.parseSource(SearchService.java:613) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.createContext(SearchService.java:481) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:457) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:253) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:330) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:327) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.transport.TcpTransport$RequestHandler.doRun(TcpTransport.java:1544) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638) ~[elasticsearch-5.5.0.jar:5.5.0]
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.5.0.jar:5.5.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[?:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[?:1.8.0_121]
        at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_121]

@elasticmachine
Copy link
Copy Markdown
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

Copy link
Copy Markdown
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to RangeFieldTypeTests?

@scincowork
Copy link
Copy Markdown
Author

I created issue #25950 for this so I can reference it in tests.

@jpountz I'm not quite sure what kind of test to write in RangeFieldTypeTests, but would one in SearchQueryIT make more sense? At least in there I can test to ensure the query doesn't fail, right?

@jpountz
Copy link
Copy Markdown
Contributor

jpountz commented Jul 28, 2017

I'd rather like a unit test, maybe you can have a look at the existing tests we have for range queries in that test and make one for termQuery?

@scincowork scincowork force-pushed the fixTermQueryForRanges branch from 05e84ae to 1c8e911 Compare July 28, 2017 18:07
@scincowork
Copy link
Copy Markdown
Author

@jpountz Done

@jpountz
Copy link
Copy Markdown
Contributor

jpountz commented Jul 31, 2017

@scinconovetta Thanks!
@elasticmachine Test it please.

@jpountz jpountz merged commit e0359e7 into elastic:master Jul 31, 2017
jpountz pushed a commit that referenced this pull request Jul 31, 2017
jpountz pushed a commit that referenced this pull request Jul 31, 2017
jpountz pushed a commit that referenced this pull request Jul 31, 2017
@jpountz jpountz added :Search/Search Search-related issues that do not fall into other categories v5.6.0 v6.0.0 labels Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search/Search Search-related issues that do not fall into other categories v5.6.0 v6.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants