Search in sources :

Example 1 with InternalExtendedStats

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

Example 2 with InternalExtendedStats

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

Aggregations

InternalExtendedStats (org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats)2 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 ExtendedStatsAggregationBuilder (org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder)1