Search in sources :

Example 1 with StatsAggregationBuilder

use of org.opensearch.search.aggregations.metrics.StatsAggregationBuilder in project fess by codelibs.

the class EsAbstractConditionAggregation method regStatsA.

protected StatsAggregationBuilder regStatsA(String name, String field) {
    StatsAggregationBuilder builder = AggregationBuilders.stats(name).field(field);
    regA(builder);
    return builder;
}
Also used : ExtendedStatsAggregationBuilder(org.opensearch.search.aggregations.metrics.ExtendedStatsAggregationBuilder) StatsAggregationBuilder(org.opensearch.search.aggregations.metrics.StatsAggregationBuilder)

Example 2 with StatsAggregationBuilder

use of org.opensearch.search.aggregations.metrics.StatsAggregationBuilder in project OpenSearch by opensearch-project.

the class VariableWidthHistogramAggregatorTests method testComplexSubAggregations.

public void testComplexSubAggregations() throws IOException {
    final List<Number> dataset = Arrays.asList(5, 4, 3, 2, 1, 0, 6, 7, 8, 9, 10, 11);
    testSearchCase(DEFAULT_QUERY, dataset, false, aggregation -> aggregation.field(NUMERIC_FIELD).setNumBuckets(3).setInitialBuffer(12).setShardSize(4).subAggregation(new StatsAggregationBuilder("stats").field(NUMERIC_FIELD)), histogram -> {
        double deltaError = 1d / 10000d;
        // Expected clusters: [ (0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11) ]
        InternalStats stats = histogram.getBuckets().get(0).getAggregations().get("stats");
        assertEquals(0d, stats.getMin(), deltaError);
        assertEquals(3L, stats.getMax(), deltaError);
        assertEquals(4L, stats.getCount());
        assertTrue(AggregationInspectionHelper.hasValue(stats));
        stats = histogram.getBuckets().get(1).getAggregations().get("stats");
        assertEquals(4d, stats.getMin(), deltaError);
        assertEquals(7d, stats.getMax(), deltaError);
        assertEquals(4L, stats.getCount());
        assertTrue(AggregationInspectionHelper.hasValue(stats));
        stats = histogram.getBuckets().get(2).getAggregations().get("stats");
        assertEquals(8d, stats.getMin(), deltaError);
        assertEquals(11d, stats.getMax(), deltaError);
        assertEquals(4L, stats.getCount());
        assertTrue(AggregationInspectionHelper.hasValue(stats));
    });
}
Also used : StatsAggregationBuilder(org.opensearch.search.aggregations.metrics.StatsAggregationBuilder) InternalStats(org.opensearch.search.aggregations.metrics.InternalStats)

Example 3 with StatsAggregationBuilder

use of org.opensearch.search.aggregations.metrics.StatsAggregationBuilder in project OpenSearch by opensearch-project.

the class VariableWidthHistogramAggregatorTests method testMultipleSegments.

public void testMultipleSegments() throws IOException {
    final List<Number> dataset = Arrays.asList(1001, 1002, 1, 2, 1003, 3, 1004, 1005, 4, 5);
    // There should be two clusters: (1, 2, 3, 4, 5) and (1001, 1002, 1003, 1004, 1005)
    // We can't enable multiple segments per index for many of the tests above, because the clusters are too close.
    // Slight randomization --> different caches in the aggregator --> different clusters
    // However, these two clusters are so far apart that even if a doc from one ends up in the other,
    // the centroids will not change much.
    // To account for this case of a document switching clusters, we check that each cluster centroid is within
    // a certain range, rather than asserting exact values.
    testSearchCase(DEFAULT_QUERY, dataset, true, aggregation -> aggregation.field(NUMERIC_FIELD).setNumBuckets(2).setInitialBuffer(4).setShardSize(3).subAggregation(new StatsAggregationBuilder("stats").field(NUMERIC_FIELD)), histogram -> {
        final List<InternalVariableWidthHistogram.Bucket> buckets = histogram.getBuckets();
        double deltaError = 1d / 10000d;
        assertEquals(2, buckets.size());
        // The lower cluster
        assertThat(buckets.get(0).getDocCount(), both(greaterThanOrEqualTo(4L)).and(lessThanOrEqualTo(7L)));
        assertThat(buckets.get(0).centroid(), both(greaterThanOrEqualTo(0.0)).and(lessThanOrEqualTo(300.0)));
        assertEquals(1, buckets.get(0).min(), deltaError);
        // The higher cluster
        assertThat(buckets.get(1).getDocCount(), equalTo(dataset.size() - buckets.get(0).getDocCount()));
        assertThat(buckets.get(1).centroid(), both(greaterThanOrEqualTo(800.0)).and(lessThanOrEqualTo(1005.0)));
        assertEquals(1005, buckets.get(1).max(), deltaError);
    });
}
Also used : StatsAggregationBuilder(org.opensearch.search.aggregations.metrics.StatsAggregationBuilder)

Example 4 with StatsAggregationBuilder

use of org.opensearch.search.aggregations.metrics.StatsAggregationBuilder in project OpenSearch by opensearch-project.

the class DerivativeAggregatorTests method testMultiValueAggDerivative.

public void testMultiValueAggDerivative() throws IOException {
    setupValueCounts();
    Query query = new MatchAllDocsQuery();
    HistogramAggregationBuilder aggBuilder = new HistogramAggregationBuilder("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval);
    aggBuilder.subAggregation(new StatsAggregationBuilder("stats").field(SINGLE_VALUED_FIELD_NAME));
    aggBuilder.subAggregation(new DerivativePipelineAggregationBuilder("deriv", "stats.sum"));
    executeTestCase(query, aggBuilder, histogram -> {
        assertThat(histogram, notNullValue());
        assertThat(histogram.getName(), equalTo("histo"));
        List<? extends Histogram.Bucket> buckets = ((Histogram) histogram).getBuckets();
        assertThat(buckets.size(), equalTo(numValueBuckets));
        assertThat(histogram, notNullValue());
        assertThat(histogram.getName(), equalTo("histo"));
        Object[] propertiesKeys = (Object[]) ((InternalAggregation) histogram).getProperty("_key");
        Object[] propertiesDocCounts = (Object[]) ((InternalAggregation) histogram).getProperty("_count");
        Object[] propertiesSumCounts = (Object[]) ((InternalAggregation) histogram).getProperty("stats.sum");
        // start value, gets
        Long expectedSumPreviousBucket = Long.MIN_VALUE;
        // overwritten
        for (int i = 0; i < numValueBuckets; ++i) {
            Histogram.Bucket bucket = buckets.get(i);
            checkBucketKeyAndDocCount("InternalBucket " + i, bucket, i * interval, valueCounts[i]);
            Stats stats = bucket.getAggregations().get("stats");
            assertThat(stats, notNullValue());
            long expectedSum = valueCounts[i] * (i * interval);
            assertThat(stats.getSum(), equalTo((double) expectedSum));
            SimpleValue sumDeriv = bucket.getAggregations().get("deriv");
            if (i > 0) {
                assertThat(sumDeriv, notNullValue());
                long sumDerivValue = expectedSum - expectedSumPreviousBucket;
                assertThat(sumDeriv.value(), equalTo((double) sumDerivValue));
                assertThat(((InternalMultiBucketAggregation.InternalBucket) bucket).getProperty("histo", AggregationPath.parse("deriv.value").getPathElementsAsStringList()), equalTo((double) sumDerivValue));
            } else {
                assertThat(sumDeriv, nullValue());
            }
            expectedSumPreviousBucket = expectedSum;
            assertThat(propertiesKeys[i], equalTo((double) i * interval));
            assertThat((long) propertiesDocCounts[i], equalTo(valueCounts[i]));
            assertThat((double) propertiesSumCounts[i], equalTo((double) expectedSum));
        }
    });
}
Also used : HistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) Histogram(org.opensearch.search.aggregations.bucket.histogram.Histogram) StatsAggregationBuilder(org.opensearch.search.aggregations.metrics.StatsAggregationBuilder) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Stats(org.opensearch.search.aggregations.metrics.Stats) InternalMultiBucketAggregation(org.opensearch.search.aggregations.InternalMultiBucketAggregation)

Example 5 with StatsAggregationBuilder

use of org.opensearch.search.aggregations.metrics.StatsAggregationBuilder in project fess by codelibs.

the class EsAbstractConditionAggregation method regStatsA.

protected StatsAggregationBuilder regStatsA(String name, String field) {
    StatsAggregationBuilder builder = AggregationBuilders.stats(name).field(field);
    regA(builder);
    return builder;
}
Also used : ExtendedStatsAggregationBuilder(org.opensearch.search.aggregations.metrics.ExtendedStatsAggregationBuilder) StatsAggregationBuilder(org.opensearch.search.aggregations.metrics.StatsAggregationBuilder)

Aggregations

StatsAggregationBuilder (org.opensearch.search.aggregations.metrics.StatsAggregationBuilder)7 ExtendedStatsAggregationBuilder (org.opensearch.search.aggregations.metrics.ExtendedStatsAggregationBuilder)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 BoolQueryBuilder (org.opensearch.index.query.BoolQueryBuilder)1 BoostingQueryBuilder (org.opensearch.index.query.BoostingQueryBuilder)1 CommonTermsQueryBuilder (org.opensearch.index.query.CommonTermsQueryBuilder)1 ConstantScoreQueryBuilder (org.opensearch.index.query.ConstantScoreQueryBuilder)1 DisMaxQueryBuilder (org.opensearch.index.query.DisMaxQueryBuilder)1 DistanceFeatureQueryBuilder (org.opensearch.index.query.DistanceFeatureQueryBuilder)1 ExistsQueryBuilder (org.opensearch.index.query.ExistsQueryBuilder)1 FieldMaskingSpanQueryBuilder (org.opensearch.index.query.FieldMaskingSpanQueryBuilder)1 FuzzyQueryBuilder (org.opensearch.index.query.FuzzyQueryBuilder)1 GeoBoundingBoxQueryBuilder (org.opensearch.index.query.GeoBoundingBoxQueryBuilder)1 GeoDistanceQueryBuilder (org.opensearch.index.query.GeoDistanceQueryBuilder)1 GeoPolygonQueryBuilder (org.opensearch.index.query.GeoPolygonQueryBuilder)1 GeoShapeQueryBuilder (org.opensearch.index.query.GeoShapeQueryBuilder)1 IdsQueryBuilder (org.opensearch.index.query.IdsQueryBuilder)1 IntervalQueryBuilder (org.opensearch.index.query.IntervalQueryBuilder)1 MatchAllQueryBuilder (org.opensearch.index.query.MatchAllQueryBuilder)1