diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/ChildCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/ChildCollector.java index 217f2dde955..a445a1453be 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/ChildCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/ChildCollector.java @@ -24,6 +24,7 @@ import org.apache.lucene.search.Collector; import org.apache.lucene.search.Scorer; import org.apache.lucene.util.OpenBitSet; import org.elasticsearch.common.BytesWrap; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.index.cache.id.IdReaderTypeCache; import org.elasticsearch.search.internal.SearchContext; @@ -40,7 +41,7 @@ public class ChildCollector extends Collector { private final SearchContext context; - private final Map typeCacheMap; + private final Tuple[] readers; private final Map parentDocs; @@ -52,9 +53,10 @@ public class ChildCollector extends Collector { this.parentDocs = new HashMap(); // create a specific type map lookup for faster lookup operations per doc - this.typeCacheMap = new HashMap(context.searcher().subReaders().length); - for (IndexReader indexReader : context.searcher().subReaders()) { - typeCacheMap.put(indexReader.getCoreCacheKey(), context.idCache().reader(indexReader).type(parentType)); + this.readers = new Tuple[context.searcher().subReaders().length]; + for (int i = 0; i < readers.length; i++) { + IndexReader reader = context.searcher().subReaders()[i]; + readers[i] = new Tuple(reader, context.idCache().reader(reader).type(parentType)); } } @@ -71,8 +73,9 @@ public class ChildCollector extends Collector { if (parentId == null) { return; } - for (IndexReader indexReader : context.searcher().subReaders()) { - IdReaderTypeCache idReaderTypeCache = typeCacheMap.get(indexReader.getCoreCacheKey()); + for (Tuple tuple : readers) { + IndexReader indexReader = tuple.v1(); + IdReaderTypeCache idReaderTypeCache = tuple.v2(); if (idReaderTypeCache == null) { // might be if we don't have that doc with that type in this reader continue; } @@ -90,7 +93,7 @@ public class ChildCollector extends Collector { } @Override public void setNextReader(IndexReader reader, int docBase) throws IOException { - typeCache = typeCacheMap.get(reader.getCoreCacheKey()); + typeCache = context.idCache().reader(reader).type(parentType); } @Override public boolean acceptsDocsOutOfOrder() { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/HasChildFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/HasChildFilter.java index 1e229d0b8cd..fefcd39001c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/HasChildFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/type/child/HasChildFilter.java @@ -81,11 +81,8 @@ public class HasChildFilter extends Filter implements ScopePhase.CollectorPhase } @Override public DocIdSet getDocIdSet(IndexReader reader) throws IOException { - DocIdSet docIdSet = parentDocs.get(reader.getCoreCacheKey()); - if (docIdSet == null) { - return DocIdSet.EMPTY_DOCIDSET; - } - return docIdSet; + // ok to return null + return parentDocs.get(reader.getCoreCacheKey()); } @Override public String toString() {