Search in sources :

Example 31 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class InternalSingleBucketAggregation method doReduce.

@Override
public InternalAggregation doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    long docCount = 0L;
    List<InternalAggregations> subAggregationsList = new ArrayList<>(aggregations.size());
    for (InternalAggregation aggregation : aggregations) {
        assert aggregation.getName().equals(getName());
        docCount += ((InternalSingleBucketAggregation) aggregation).docCount;
        subAggregationsList.add(((InternalSingleBucketAggregation) aggregation).aggregations);
    }
    final InternalAggregations aggs = InternalAggregations.reduce(subAggregationsList, reduceContext);
    return newAggregation(getName(), docCount, aggs);
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) InternalAggregations(org.elasticsearch.search.aggregations.InternalAggregations) ArrayList(java.util.ArrayList)

Example 32 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class InternalSingleBucketAggregation method getProperty.

@Override
public Object getProperty(List<String> path) {
    if (path.isEmpty()) {
        return this;
    } else {
        String aggName = path.get(0);
        if (aggName.equals("_count")) {
            if (path.size() > 1) {
                throw new IllegalArgumentException("_count must be the last element in the path");
            }
            return getDocCount();
        }
        InternalAggregation aggregation = aggregations.get(aggName);
        if (aggregation == null) {
            throw new IllegalArgumentException("Cannot find an aggregation named [" + aggName + "] in [" + getName() + "]");
        }
        return aggregation.getProperty(path.subList(1, path.size()));
    }
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation)

Example 33 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class InternalAdjacencyMatrix method doReduce.

@Override
public InternalAggregation doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    Map<String, List<InternalBucket>> bucketsMap = new HashMap<>();
    for (InternalAggregation aggregation : aggregations) {
        InternalAdjacencyMatrix filters = (InternalAdjacencyMatrix) aggregation;
        for (InternalBucket bucket : filters.buckets) {
            List<InternalBucket> sameRangeList = bucketsMap.get(bucket.key);
            if (sameRangeList == null) {
                sameRangeList = new ArrayList<>(aggregations.size());
                bucketsMap.put(bucket.key, sameRangeList);
            }
            sameRangeList.add(bucket);
        }
    }
    ArrayList<InternalBucket> reducedBuckets = new ArrayList<>(bucketsMap.size());
    for (List<InternalBucket> sameRangeList : bucketsMap.values()) {
        InternalBucket reducedBucket = sameRangeList.get(0).reduce(sameRangeList, reduceContext);
        if (reducedBucket.docCount >= 1) {
            reducedBuckets.add(reducedBucket);
        }
    }
    Collections.sort(reducedBuckets, Comparator.comparing(InternalBucket::getKey));
    InternalAdjacencyMatrix reduced = new InternalAdjacencyMatrix(name, reducedBuckets, pipelineAggregators(), getMetaData());
    return reduced;
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

InternalAggregation (org.elasticsearch.search.aggregations.InternalAggregation)33 ArrayList (java.util.ArrayList)23 List (java.util.List)16 Map (java.util.Map)10 InternalAggregations (org.elasticsearch.search.aggregations.InternalAggregations)10 IOException (java.io.IOException)8 Collectors (java.util.stream.Collectors)8 PipelineAggregator (org.elasticsearch.search.aggregations.pipeline.PipelineAggregator)8 StreamSupport (java.util.stream.StreamSupport)7 StreamInput (org.elasticsearch.common.io.stream.StreamInput)7 ReduceContext (org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext)7 Bucket (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket)7 InternalSimpleValue (org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue)6 HashMap (java.util.HashMap)5 DocValueFormat (org.elasticsearch.search.DocValueFormat)5 StreamOutput (org.elasticsearch.common.io.stream.StreamOutput)4 Settings (org.elasticsearch.common.settings.Settings)4 SignificanceHeuristic (org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic)4 GapPolicy (org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy)4 BucketHelpers.resolveBucketValue (org.elasticsearch.search.aggregations.pipeline.BucketHelpers.resolveBucketValue)4