@@ -231,6 +231,7 @@ public SearchPhaseController.ReducedQueryPhase reduce() throws Exception {
231231 while ((batchedResult = batchedResults .poll ()) != null ) {
232232 topDocsStats .add (batchedResult .v1 ());
233233 consumePartialMergeResult (batchedResult .v2 (), topDocsList , aggsList );
234+ // Add the estimate of the agg size
234235 addEstimateAndMaybeBreak (batchedResult .v2 ().estimatedSize );
235236 }
236237 for (QuerySearchResult result : buffer ) {
@@ -458,12 +459,13 @@ private long ramBytesUsedQueryResult(QuerySearchResult result) {
458459 * Returns an estimation of the size that a reduce of the provided size
459460 * would take on memory.
460461 * This size is estimated as roughly 1.5 times the size of the serialized
461- * aggregations that need to be reduced. This estimation can be completely
462- * off for some aggregations but it is corrected with the real size after
463- * the reduce completes.
462+ * aggregations that need to be reduced.
463+ * This method expects an already accounted size, so only an extra 0.5x is returned.
464+ * This estimation can be completely off for some aggregations
465+ * but it is corrected with the real size after the reduce completes.
464466 */
465467 private static long estimateRamBytesUsedForReduce (long size ) {
466- return Math .round (1 .5d * size );
468+ return Math .round (0 .5d * size );
467469 }
468470
469471 private void consume (QuerySearchResult result , Runnable next ) {
0 commit comments