Search in sources :

Example 26 with InternalAggregation

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

the class InternalAvg method reduce.

@Override
public InternalAvg reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    CompensatedSum kahanSummation = new CompensatedSum(0, 0);
    long count = 0;
    // accurate than naive summation.
    for (InternalAggregation aggregation : aggregations) {
        InternalAvg avg = (InternalAvg) aggregation;
        count += avg.count;
        kahanSummation.add(avg.sum);
    }
    return new InternalAvg(getName(), kahanSummation.value(), count, format, getMetadata());
}
Also used : InternalAggregation(org.opensearch.search.aggregations.InternalAggregation)

Example 27 with InternalAggregation

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

the class InternalMedianAbsoluteDeviation method reduce.

@Override
public InternalAggregation reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    final TDigestState valueMerged = new TDigestState(valuesSketch.compression());
    for (InternalAggregation aggregation : aggregations) {
        final InternalMedianAbsoluteDeviation madAggregation = (InternalMedianAbsoluteDeviation) aggregation;
        valueMerged.add(madAggregation.valuesSketch);
    }
    return new InternalMedianAbsoluteDeviation(name, metadata, format, valueMerged);
}
Also used : InternalAggregation(org.opensearch.search.aggregations.InternalAggregation)

Example 28 with InternalAggregation

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

the class InternalGeoBounds method reduce.

@Override
public InternalAggregation reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    double top = Double.NEGATIVE_INFINITY;
    double bottom = Double.POSITIVE_INFINITY;
    double posLeft = Double.POSITIVE_INFINITY;
    double posRight = Double.NEGATIVE_INFINITY;
    double negLeft = Double.POSITIVE_INFINITY;
    double negRight = Double.NEGATIVE_INFINITY;
    for (InternalAggregation aggregation : aggregations) {
        InternalGeoBounds bounds = (InternalGeoBounds) aggregation;
        if (bounds.top > top) {
            top = bounds.top;
        }
        if (bounds.bottom < bottom) {
            bottom = bounds.bottom;
        }
        if (bounds.posLeft < posLeft) {
            posLeft = bounds.posLeft;
        }
        if (bounds.posRight > posRight) {
            posRight = bounds.posRight;
        }
        if (bounds.negLeft < negLeft) {
            negLeft = bounds.negLeft;
        }
        if (bounds.negRight > negRight) {
            negRight = bounds.negRight;
        }
    }
    return new InternalGeoBounds(name, top, bottom, posLeft, posRight, negLeft, negRight, wrapLongitude, getMetadata());
}
Also used : InternalAggregation(org.opensearch.search.aggregations.InternalAggregation)

Example 29 with InternalAggregation

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

the class InternalSum method reduce.

@Override
public InternalSum reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    // Compute the sum of double values with Kahan summation algorithm which is more
    // accurate than naive summation.
    CompensatedSum kahanSummation = new CompensatedSum(0, 0);
    for (InternalAggregation aggregation : aggregations) {
        double value = ((InternalSum) aggregation).sum;
        kahanSummation.add(value);
    }
    return new InternalSum(name, kahanSummation.value(), format, getMetadata());
}
Also used : InternalAggregation(org.opensearch.search.aggregations.InternalAggregation)

Example 30 with InternalAggregation

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

the class AbstractInternalHDRPercentiles method reduce.

@Override
public AbstractInternalHDRPercentiles reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    DoubleHistogram merged = null;
    for (InternalAggregation aggregation : aggregations) {
        final AbstractInternalHDRPercentiles percentiles = (AbstractInternalHDRPercentiles) aggregation;
        if (merged == null) {
            merged = new DoubleHistogram(percentiles.state);
            merged.setAutoResize(true);
        }
        merged.add(percentiles.state);
    }
    return createReduced(getName(), keys, merged, keyed, getMetadata());
}
Also used : InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) DoubleHistogram(org.HdrHistogram.DoubleHistogram)

Aggregations

InternalAggregation (org.opensearch.search.aggregations.InternalAggregation)75 ArrayList (java.util.ArrayList)40 List (java.util.List)17 SearchResponse (org.opensearch.action.search.SearchResponse)11 InternalAggregations (org.opensearch.search.aggregations.InternalAggregations)11 Global (org.opensearch.search.aggregations.bucket.global.Global)11 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)11 NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 MockBigArrays (org.opensearch.common.util.MockBigArrays)9 MockPageCacheRecycler (org.opensearch.common.util.MockPageCacheRecycler)9 IOException (java.io.IOException)8 ScriptService (org.opensearch.script.ScriptService)8 DocValueFormat (org.opensearch.search.DocValueFormat)8 ReduceContext (org.opensearch.search.aggregations.InternalAggregation.ReduceContext)8 Collectors (java.util.stream.Collectors)7 MultiBucketConsumerService (org.opensearch.search.aggregations.MultiBucketConsumerService)7 IndexReader (org.apache.lucene.index.IndexReader)6 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)6