Search in sources :

Example 1 with SiblingPipelineAggregator

use of org.opensearch.search.aggregations.pipeline.SiblingPipelineAggregator in project OpenSearch by opensearch-project.

the class InternalAggregations method topLevelReduce.

/**
 * Begin the reduction process.  This should be the entry point for the "first" reduction, e.g. called by
 * SearchPhaseController or anywhere else that wants to initiate a reduction.  It _should not_ be called
 * as an intermediate reduction step (e.g. in the middle of an aggregation tree).
 *
 * This method first reduces the aggregations, and if it is the final reduce, then reduce the pipeline
 * aggregations (both embedded parent/sibling as well as top-level sibling pipelines)
 */
public static InternalAggregations topLevelReduce(List<InternalAggregations> aggregationsList, ReduceContext context) {
    InternalAggregations reduced = reduce(aggregationsList, context, reducedAggregations -> new InternalAggregations(reducedAggregations, context.pipelineTreeForBwcSerialization()));
    if (reduced == null) {
        return null;
    }
    if (context.isFinalReduce()) {
        List<InternalAggregation> reducedInternalAggs = reduced.getInternalAggregations();
        reducedInternalAggs = reducedInternalAggs.stream().map(agg -> agg.reducePipelines(agg, context, context.pipelineTreeRoot().subTree(agg.getName()))).collect(Collectors.toList());
        for (PipelineAggregator pipelineAggregator : context.pipelineTreeRoot().aggregators()) {
            SiblingPipelineAggregator sib = (SiblingPipelineAggregator) pipelineAggregator;
            InternalAggregation newAgg = sib.doReduce(from(reducedInternalAggs), context);
            reducedInternalAggs.add(newAgg);
        }
        return from(reducedInternalAggs);
    }
    return reduced;
}
Also used : SiblingPipelineAggregator(org.opensearch.search.aggregations.pipeline.SiblingPipelineAggregator) SiblingPipelineAggregator(org.opensearch.search.aggregations.pipeline.SiblingPipelineAggregator) PipelineAggregator(org.opensearch.search.aggregations.pipeline.PipelineAggregator)

Aggregations

PipelineAggregator (org.opensearch.search.aggregations.pipeline.PipelineAggregator)1 SiblingPipelineAggregator (org.opensearch.search.aggregations.pipeline.SiblingPipelineAggregator)1