Fix NPE/AIOOBE when building a bucket which has not been collected.

Close #5048
This commit is contained in:
Adrien Grand 2014-02-25 12:20:58 +01:00
parent 66b589d58e
commit 610694446a
1 changed files with 7 additions and 1 deletions

View File

@ -119,7 +119,13 @@ public class AggregatorFactories {
@Override
public InternalAggregation buildAggregation(long owningBucketOrdinal) {
return aggregators.get(owningBucketOrdinal).buildAggregation(0);
// The bucket ordinal may be out of range in case of eg. a terms/filter/terms where
// the filter matches no document in the highest buckets of the first terms agg
if (owningBucketOrdinal >= aggregators.size() || aggregators.get(owningBucketOrdinal) == null) {
return first.buildEmptyAggregation();
} else {
return aggregators.get(owningBucketOrdinal).buildAggregation(0);
}
}
@Override