use of org.elasticsearch.search.aggregations.metrics.stats.InternalStats in project elasticsearch by elastic.
the class InternalExtendedStats method doReduce.
@Override
public InternalExtendedStats doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
double sumOfSqrs = 0;
for (InternalAggregation aggregation : aggregations) {
InternalExtendedStats stats = (InternalExtendedStats) aggregation;
if (stats.sigma != sigma) {
throw new IllegalStateException("Cannot reduce other stats aggregations that have a different sigma");
}
sumOfSqrs += stats.getSumOfSquares();
}
final InternalStats stats = super.doReduce(aggregations, reduceContext);
return new InternalExtendedStats(name, stats.getCount(), stats.getSum(), stats.getMin(), stats.getMax(), sumOfSqrs, sigma, format, pipelineAggregators(), getMetaData());
}
use of org.elasticsearch.search.aggregations.metrics.stats.InternalStats in project elasticsearch by elastic.
the class InternalStatsTests method assertReduced.
@Override
protected void assertReduced(InternalStats reduced, List<InternalStats> inputs) {
long expectedCount = 0;
double expectedSum = 0;
double expectedMin = Double.POSITIVE_INFINITY;
double expectedMax = Double.NEGATIVE_INFINITY;
for (InternalStats stats : inputs) {
expectedCount += stats.getCount();
if (Double.compare(stats.getMin(), expectedMin) < 0) {
expectedMin = stats.getMin();
}
if (Double.compare(stats.getMax(), expectedMax) > 0) {
expectedMax = stats.getMax();
}
expectedSum += stats.getSum();
}
assertEquals(expectedCount, reduced.getCount());
assertEquals(expectedSum, reduced.getSum(), 1e-10);
assertEquals(expectedMin, reduced.getMin(), 0d);
assertEquals(expectedMax, reduced.getMax(), 0d);
}
use of org.elasticsearch.search.aggregations.metrics.stats.InternalStats in project elasticsearch by elastic.
the class StatsAggregatorTests method testCase.
public void testCase(MappedFieldType ft, CheckedConsumer<RandomIndexWriter, IOException> buildIndex, Consumer<InternalStats> verify) throws IOException {
try (Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
buildIndex.accept(indexWriter);
try (IndexReader reader = indexWriter.getReader()) {
IndexSearcher searcher = new IndexSearcher(reader);
StatsAggregationBuilder aggBuilder = new StatsAggregationBuilder("my_agg").field("field");
InternalStats stats = search(searcher, new MatchAllDocsQuery(), aggBuilder, ft);
verify.accept(stats);
}
}
}
Aggregations