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);
}
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()));
}
}
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;
}
Aggregations