Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE for has_child query if number of results exceed certain limit #4135

Closed
ajhalani opened this issue Nov 8, 2013 · 3 comments
Closed

NPE for has_child query if number of results exceed certain limit #4135

ajhalani opened this issue Nov 8, 2013 · 3 comments

Comments

@ajhalani
Copy link

ajhalani commented Nov 8, 2013

If the number of results exceed a certain limit, has_child query throws a NullPointerException.

curl -x '' -s -XPOST "http://localhost:9200/myindex/vendor/_search?from=0&size=20&pretty=true&routing=0" -d '{
   "query" : {
      "has_child" : {
         "query" : {
            "query_string" : { "query" : "signed_date:[now-120d TO now-90d]" }
         },
         "type" : "transaction"
      }
   }
}
'

[2013-11-08 15:01:41,825][DEBUG][action.search.type       ] [Phage] [myindex_20131108][1], node[fuBzjMWDQgmr_qm0cVLIog], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@23b13dc6]
org.elasticsearch.transport.RemoteTransportException: [Ch'od][inet[/192.168.175.128:9301]][search/phase/query+fetch]
Caused by: org.elasticsearch.search.query.QueryPhaseExecutionException: [myindex_20131108][1]: query[filtered(child_filter[transaction/vendor](filtered(signed_date:[1373572895448 TO 1376164895448])->cache(_type:transaction)))->cache(_type:vendor)],from[0],size[20]: Query Failed [Failed to execute main query]
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:123)
        at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:306)
        at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:686)
        at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:1)
        at org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.run(MessageChannelHandler.java:270)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
        at org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter.getDocIdSet(ApplyAcceptedDocsFilter.java:45)
        at org.elasticsearch.index.search.child.ChildrenConstantScoreQuery$ParentWeight.scorer(ChildrenConstantScoreQuery.java:178)
        at org.apache.lucene.search.FilteredQuery$RandomAccessFilterStrategy.filteredScorer(FilteredQuery.java:533)
        at org.apache.lucene.search.FilteredQuery$1.scorer(FilteredQuery.java:133)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:624)
        at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:167)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:119)
        ... 7 more
[2013-11-08 15:01:41,827][DEBUG][action.search.type       ] [Phage] All shards failed for phase: [query_fetch]

I debugged the code and found the issue happens due to class ChildrenConstantScoreQuery.java, line #115 is passing null shortCircuitFilter. This happens when remaining value > 8192 so it's not initialized

        Filter shortCircuitFilter = null;
        if (remaining == 1) {
            BytesRef id = collectedUids.v().iterator().next().value.toBytesRef();
            shortCircuitFilter = new TermFilter(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(parentType, id)));
        } else if (remaining <= shortCircuitParentDocSet) {
            shortCircuitFilter = new ParentIdsFilter(parentType, collectedUids.v().keys, collectedUids.v().allocated);
        }

        ParentWeight parentWeight = new ParentWeight(parentFilter, shortCircuitFilter, searchContext, collectedUids);

This is bug introduced after 0.90.1 as the query was running fine in past. Thanks!

@s1monw
Copy link
Contributor

s1monw commented Nov 8, 2013

@martijnvg can you look into this?

@martijnvg
Copy link
Member

Thanks for reporting this issue @ajhalani! We will fix this soon.

@ajhalani
Copy link
Author

You got it, thanks for getting to it quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants