private void mapSegmentCountsToGlobalCounts() {
// There is no public method in Ordinals.Docs that allows for this mapping...
// This is the cleanest way I can think of so far
GlobalOrdinalMapping mapping;
if (globalOrds instanceof GlobalOrdinalMapping) {
mapping = (GlobalOrdinalMapping) globalOrds;
} else {
assert globalOrds.getValueCount() == segmentOrds.getValueCount();
mapping = null;
}
for (long i = 1; i < segmentDocCounts.size(); i++) {
final int inc = segmentDocCounts.set(i, 0);
if (inc == 0) {
continue;
}
final long ord = i - 1; // remember we do +1 when counting
final long globalOrd = mapping == null ? ord : mapping.getGlobalOrd(ord);
try {
incrementBucketDocCount(globalOrd, inc);
} catch (IOException e) {
throw ExceptionsHelper.convertToElastic(e);
}