Nested: Make sure queries/filters/aggs get a FixedBitSet when they expect one.

Close #6279
This commit is contained in:
Adrien Grand 2014-05-22 15:13:11 +02:00
parent b3274bd770
commit 6e49256fa8
4 changed files with 19 additions and 1 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
import org.elasticsearch.common.Strings;
@ -150,6 +151,9 @@ public class NestedFilterParser implements FilterParser {
//}
parentFilter = parseContext.cacheFilter(parentFilter, null);
}
// if the filter cache is disabled, then we still have a filter that is not cached while ToParentBlockJoinQuery
// expects FixedBitSet instances
parentFilter = new FixedBitSetCachingWrapperFilter(parentFilter);
Filter nestedFilter;
if (join) {

View File

@ -23,6 +23,7 @@ import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
import org.apache.lucene.util.Bits;
@ -154,6 +155,9 @@ public class NestedQueryParser implements QueryParser {
//}
parentFilter = parseContext.cacheFilter(parentFilter, null);
}
// if the filter cache is disabled, then we still have a filter that is not cached while ToParentBlockJoinQuery
// expects FixedBitSet instances
parentFilter = new FixedBitSetCachingWrapperFilter(parentFilter);
ToParentBlockJoinQuery joinQuery = new ToParentBlockJoinQuery(query, parentFilter, scoreMode);
joinQuery.setBoost(boost);

View File

@ -25,6 +25,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.lucene.docset.DocIdSets;
import java.io.IOException;
import java.util.Collection;
@ -117,7 +118,13 @@ public class IncludeNestedDocsQuery extends Query {
return null;
}
if (!(parents instanceof FixedBitSet)) {
if (parents.isCacheable()) {
// the filter is cached, yet not with the right type
throw new IllegalStateException("parentFilter must return FixedBitSet; got " + parents);
} else {
// may happen if the filter cache type is none
parents = DocIdSets.toFixedBitSet(parents.iterator(), context.reader().maxDoc());
}
}
int firstParentDoc = parentScorer.nextDoc();

View File

@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.bucket.nested;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.lucene.ReaderContextAware;
@ -82,6 +83,8 @@ public class NestedAggregator extends SingleBucketAggregator implements ReaderCo
parentFilterNotCached = closestNestedAggregator.childFilter;
}
parentFilter = SearchContext.current().filterCache().cache(parentFilterNotCached);
// if the filter cache is disabled, we still need to produce bit sets
parentFilter = new FixedBitSetCachingWrapperFilter(parentFilter);
}
try {