@@ -561,7 +561,7 @@ private InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws
561561 BucketUpdater <TB > updater = bucketUpdater (owningBucketOrds [ordIdx ]);
562562 collectionStrategy .forEach (owningBucketOrds [ordIdx ], new BucketInfoConsumer () {
563563 TB spare = null ;
564-
564+
565565 @ Override
566566 public void accept (long globalOrd , long bucketOrd , long docCount ) throws IOException {
567567 otherDocCount [finalOrdIdx ] += docCount ;
@@ -574,7 +574,7 @@ public void accept(long globalOrd, long bucketOrd, long docCount) throws IOExcep
574574 }
575575 }
576576 });
577-
577+
578578 // Get the top buckets
579579 topBucketsPreOrd [ordIdx ] = buildBuckets (ordered .size ());
580580 for (int i = ordered .size () - 1 ; i >= 0 ; --i ) {
@@ -797,9 +797,14 @@ SignificantStringTerms.Bucket buildEmptyTemporaryBucket() {
797797 return new SignificantStringTerms .Bucket (new BytesRef (), 0 , 0 , 0 , 0 , null , format , 0 );
798798 }
799799
800+ private long subsetSize (long owningBucketOrd ) {
801+ // if the owningBucketOrd is not in the array that means the bucket is empty so the size has to be 0
802+ return owningBucketOrd < subsetSizes .size () ? subsetSizes .get (owningBucketOrd ) : 0 ;
803+ }
804+
800805 @ Override
801806 BucketUpdater <SignificantStringTerms .Bucket > bucketUpdater (long owningBucketOrd ) throws IOException {
802- long subsetSize = subsetSizes . get (owningBucketOrd );
807+ long subsetSize = subsetSize (owningBucketOrd );
803808 return (spare , globalOrd , bucketOrd , docCount ) -> {
804809 spare .bucketOrd = bucketOrd ;
805810 oversizedCopy (lookupGlobalOrd .apply (globalOrd ), spare .termBytes );
@@ -839,7 +844,7 @@ SignificantStringTerms buildResult(long owningBucketOrd, long otherDocCount, Sig
839844 bucketCountThresholds .getMinDocCount (),
840845 metadata (),
841846 format ,
842- subsetSizes . get (owningBucketOrd ),
847+ subsetSize (owningBucketOrd ),
843848 supersetSize ,
844849 significanceHeuristic ,
845850 Arrays .asList (topBuckets )
0 commit comments