use of org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats in project elasticsearch by elastic.
the class ExtendedStatsAggregatorTests method testCase.
public void testCase(MappedFieldType ft, CheckedConsumer<RandomIndexWriter, IOException> buildIndex, Consumer<InternalExtendedStats> 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);
ExtendedStatsAggregationBuilder aggBuilder = new ExtendedStatsAggregationBuilder("my_agg").field("field").sigma(randomDoubleBetween(0, 10, true));
InternalExtendedStats stats = search(searcher, new MatchAllDocsQuery(), aggBuilder, ft);
verify.accept(stats);
}
}
}
use of org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats in project elasticsearch by elastic.
the class InternalExtendedStatsTests method assertReduced.
@Override
protected void assertReduced(InternalExtendedStats reduced, List<InternalExtendedStats> inputs) {
long expectedCount = 0;
double expectedSum = 0;
double expectedSumOfSquare = 0;
double expectedMin = Double.POSITIVE_INFINITY;
double expectedMax = Double.NEGATIVE_INFINITY;
for (InternalExtendedStats stats : inputs) {
assertEquals(sigma, stats.getSigma(), 0);
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();
expectedSumOfSquare += stats.getSumOfSquares();
}
assertEquals(sigma, reduced.getSigma(), 0);
assertEquals(expectedCount, reduced.getCount());
assertEquals(expectedSum, reduced.getSum(), 1e-10);
assertEquals(expectedMin, reduced.getMin(), 0d);
assertEquals(expectedMax, reduced.getMax(), 0d);
assertEquals(expectedSumOfSquare, reduced.getSumOfSquares(), 1e-10);
}
Aggregations