/**
  * Utility method to return the number of documents that fell in the given bucket (identified by
  * the bucket ordinal)
  */
 public final int bucketDocCount(long bucketOrd) {
   if (bucketOrd >= docCounts.size()) {
     // This may happen eg. if no document in the highest buckets is accepted by a sub aggregator.
     // For example, if there is a long terms agg on 3 terms 1,2,3 with a sub filter aggregator and
     // if no document with 3 as a value
     // matches the filter, then the filter will never collect bucket ord 3. However, the long
     // terms agg will call bucketAggregations(3)
     // on the filter aggregator anyway to build sub-aggregations.
     return 0;
   } else {
     return docCounts.get(bucketOrd);
   }
 }
      @Override
      public int advance(int target) throws IOException {
        if (remaining == 0) {
          return currentDocId = NO_MORE_DOCS;
        }

        currentDocId = parentsIterator.advance(target);
        if (currentDocId == DocIdSetIterator.NO_MORE_DOCS) {
          return currentDocId;
        }

        bytesValues.setDocument(currentDocId);
        long index = parentIds.find(bytesValues.nextValue(), bytesValues.currentValueHash());
        if (index != -1) {
          currentScore = scores.get(index);
          currentScore /= occurrences.get(index);
          remaining--;
          return currentDocId;
        } else {
          return nextDoc();
        }
      }