NPE in nested queries with range clauses #1263

Closed
clintongormley opened this Issue Aug 19, 2011 · 6 comments

3 participants

@clintongormley
elastic member

Hiya

Using range clauses in nested queries throws an NPE, but the same query as a term query doesn't:

# [Fri Aug 19 09:55:23 2011] Protocol: http, Server: 127.0.0.2:9200
curl -XPUT 'http://127.0.0.1:9200/foo/?pretty=1'  -d '
{
   "mappings" : {
      "location" : {
         "properties" : {
            "hours" : {
               "include_in_root" : 1,
               "type" : "nested",
               "properties" : {
                  "open" : {
                     "type" : "integer"
                  },
                  "close" : {
                     "type" : "integer"
                  },
                  "day" : {
                     "index" : "not_analyzed",
                     "type" : "string"
                  }
               }
            },
            "name" : {
               "type" : "string"
            }
         }
      }
   }
}
'

# [Fri Aug 19 09:55:23 2011] Response:
# {
#    "ok" : true,
#    "acknowledged" : true
# }

# [Fri Aug 19 09:55:27 2011] Protocol: http, Server: 127.0.0.2:9200
curl -XPOST 'http://127.0.0.1:9200/foo/location?pretty=1'  -d '
{
   "hours" : [
      {
         "open" : 9,
         "close" : 12,
         "day" : "monday"
      },
      {
         "open" : 13,
         "close" : 17,
         "day" : "monday"
      }
   ],
   "name" : "Test"
}
'

# [Fri Aug 19 09:55:27 2011] Response:
# {
#    "ok" : true,
#    "_index" : "foo",
#    "_id" : "GjuRCXsVR3qZwNciqA1yuA",
#    "_type" : "location",
#    "_version" : 1
# }

# [Fri Aug 19 09:55:29 2011] Protocol: http, Server: 127.0.0.2:9200
curl -XGET 'http://127.0.0.1:9200/foo/location/_search?pretty=1'  -d '
{
   "query" : {
      "nested" : {
         "query" : {
            "bool" : {
               "must" : [
                  {
                     "text" : {
                        "hours.day" : "monday"
                     }
                  },
                  {
                     "range" : {
                        "hours.close" : {
                           "gte" : 10
                        }
                     }
                  },
                  {
                     "range" : {
                        "hours.open" : {
                           "lte" : 10
                        }
                     }
                  }
               ]
            }
         },
         "path" : "hours"
      }
   }
}
'

# [Fri Aug 19 09:55:29 2011] Response:
# {
#    "hits" : {
#       "hits" : [],
#       "max_score" : null,
#       "total" : 0
#    },
#    "timed_out" : false,
#    "_shards" : {
#       "failures" : [
#          {
#             "index" : "foo",
#             "status" : 500,
#             "reason" : "QueryPhaseExecutionException[[foo][1]: qu
# >             ery[BlockJoinQuery (filtered(+hours.day:monday +hou
# >             rs.close:[10 TO *] +hours.open:[* TO 10])->FilterCa
# >             cheFilterWrapper(_type:__hours))],from[0],size[10]:
# >              Query Failed [Failed to execute main query]]; nest
# >              ed: ",
#             "shard" : 1
#          }
#       ],
#       "failed" : 1,
#       "successful" : 4,
#       "total" : 5
#    },
#    "took" : 4
# }

And in the logs:

[09:57:37,516][DEBUG][action.search.type       ] [Andrew Gervais] [foo][4], node[Dk6W4_9GQMisu1sTfo3Zyg], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@7e383efa]
org.elasticsearch.search.query.QueryPhaseExecutionException: [foo][4]: query[BlockJoinQuery (filtered(+hours.day:monday +hours.close:[10 TO *] +hours.open:[* TO 10])->FilterCacheFilterWrapper(_type:__hours))],from[0],size[10]: Query Failed [Failed to execute main query]
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:221)
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)
    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:204)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NullPointerException
    at org.elasticsearch.index.query.NestedQueryParser$LateBindingParentFilter.getDocIdSet(NestedQueryParser.java:171)
    at org.elasticsearch.index.search.nested.BlockJoinQuery$BlockJoinWeight.scorer(BlockJoinQuery.java:171)
    at org.apache.lucene.search.FilteredQuery$1.scorer(FilteredQuery.java:116)
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:524)
    at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:198)
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:391)
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:298)
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:286)
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:217)
    ... 9 more
@kimchy
elastic member

Can't seem to recreate it on master (and it should be the same on 0.17 branch). Tried with 1 and 2 nodes. Which version does it happen for you on? Can you try on master?

@clintongormley
elastic member

Hmm, bizarre. This was failing for me every time that I ran it - I tried several versions of the range clause, and it just wouldn't work.

Since then I have upgraded to 0.17.6, and it works. I have gone back to version 0.17.4 and 0.17.5 (which I think was what i was using when I had this issue) and it still works.

Thanks for looking, I'll close this issue

@deverton

Hrm, I'm getting this issue on 0.18.1. I'll see if I can boil it down to a test case.

@deverton

Sorry, I meant 0.17.8. It fails for me with the exact test case above. Just upgraded to 0.18.1 and can't reproduce it.

@deverton

Okay, I am still seeing this on 0.18.4. It's intermittent and only affects some shards sometimes, but it's there. The test case for this issue doesn't seem to tickle it and the query I'm using is pretty big and complicated. It also uses a facet with a filter but the stack trace is exactly the same.

Caused by: java.lang.NullPointerException
    at org.elasticsearch.index.query.NestedQueryParser$LateBindingParentFilter.hashCode(NestedQueryParser.java:159)
    at org.elasticsearch.index.search.nested.BlockJoinQuery.hashCode(BlockJoinQuery.java:423)
    at org.apache.lucene.search.QueryWrapperFilter.hashCode(QueryWrapperFilter.java:72)
    at java.util.AbstractList.hashCode(AbstractList.java:527)
    at org.elasticsearch.common.lucene.search.AndFilter.hashCode(AndFilter.java:72)
@kimchy
elastic member

relates to #1536

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