Search in sources :

Example 1 with InternalStats

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());
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) InternalStats(org.elasticsearch.search.aggregations.metrics.stats.InternalStats)

Example 2 with InternalStats

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);
}
Also used : InternalStats(org.elasticsearch.search.aggregations.metrics.stats.InternalStats)

Example 3 with InternalStats

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);
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) StatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder) InternalStats(org.elasticsearch.search.aggregations.metrics.stats.InternalStats) IndexReader(org.apache.lucene.index.IndexReader) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Aggregations

InternalStats (org.elasticsearch.search.aggregations.metrics.stats.InternalStats)3 IndexReader (org.apache.lucene.index.IndexReader)1 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Directory (org.apache.lucene.store.Directory)1 InternalAggregation (org.elasticsearch.search.aggregations.InternalAggregation)1 StatsAggregationBuilder (org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder)1