Search in sources :

Example 6 with PercentilesBucket

use of org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket in project elasticsearch by elastic.

the class PercentilesBucketIT method testMetricTopLevel.

public void testMetricTopLevel() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("terms").field("tag").subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))).addAggregation(percentilesBucket("percentiles_bucket", "terms>sum").percents(PERCENTS)).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets.size(), equalTo(interval));
    double[] values = new double[interval];
    for (int i = 0; i < interval; ++i) {
        Terms.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat((String) bucket.getKey(), equalTo("tag" + (i % interval)));
        assertThat(bucket.getDocCount(), greaterThan(0L));
        Sum sum = bucket.getAggregations().get("sum");
        assertThat(sum, notNullValue());
        values[i] = sum.value();
    }
    Arrays.sort(values);
    PercentilesBucket percentilesBucketValue = response.getAggregations().get("percentiles_bucket");
    assertThat(percentilesBucketValue, notNullValue());
    assertThat(percentilesBucketValue.getName(), equalTo("percentiles_bucket"));
    assertPercentileBucket(PERCENTS, values, percentilesBucketValue);
}
Also used : PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) PipelineAggregatorBuilders.percentilesBucket(org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.percentilesBucket) PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 7 with PercentilesBucket

use of org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket in project elasticsearch by elastic.

the class PercentilesBucketIT method testNoBuckets.

public void testNoBuckets() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("terms").field("tag").includeExclude(new IncludeExclude(null, "tag.*")).subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))).addAggregation(percentilesBucket("percentiles_bucket", "terms>sum").percents(PERCENTS)).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets.size(), equalTo(0));
    PercentilesBucket percentilesBucketValue = response.getAggregations().get("percentiles_bucket");
    assertThat(percentilesBucketValue, notNullValue());
    assertThat(percentilesBucketValue.getName(), equalTo("percentiles_bucket"));
    for (Double p : PERCENTS) {
        assertThat(percentilesBucketValue.percentile(p), equalTo(Double.NaN));
    }
}
Also used : PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) PipelineAggregatorBuilders.percentilesBucket(org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.percentilesBucket) PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 8 with PercentilesBucket

use of org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket in project elasticsearch by elastic.

the class PercentilesBucketIT method testMetricAsSubAggWithInsertZeros.

public void testMetricAsSubAggWithInsertZeros() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("terms").field("tag").order(Terms.Order.term(true)).subAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).extendedBounds(minRandomValue, maxRandomValue).subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))).subAggregation(percentilesBucket("percentiles_bucket", "histo>sum").gapPolicy(BucketHelpers.GapPolicy.INSERT_ZEROS).percents(PERCENTS))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    List<Terms.Bucket> termsBuckets = terms.getBuckets();
    assertThat(termsBuckets.size(), equalTo(interval));
    for (int i = 0; i < interval; ++i) {
        Terms.Bucket termsBucket = termsBuckets.get(i);
        assertThat(termsBucket, notNullValue());
        assertThat((String) termsBucket.getKey(), equalTo("tag" + (i % interval)));
        Histogram histo = termsBucket.getAggregations().get("histo");
        assertThat(histo, notNullValue());
        assertThat(histo.getName(), equalTo("histo"));
        List<? extends Histogram.Bucket> buckets = histo.getBuckets();
        double[] values = new double[numValueBuckets];
        for (int j = 0; j < numValueBuckets; ++j) {
            Histogram.Bucket bucket = buckets.get(j);
            assertThat(bucket, notNullValue());
            assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) j * interval));
            Sum sum = bucket.getAggregations().get("sum");
            assertThat(sum, notNullValue());
            values[j] = sum.value();
        }
        Arrays.sort(values);
        PercentilesBucket percentilesBucketValue = termsBucket.getAggregations().get("percentiles_bucket");
        assertThat(percentilesBucketValue, notNullValue());
        assertThat(percentilesBucketValue.getName(), equalTo("percentiles_bucket"));
        assertPercentileBucket(PERCENTS, values, percentilesBucketValue);
    }
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) PipelineAggregatorBuilders.percentilesBucket(org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.percentilesBucket) PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 9 with PercentilesBucket

use of org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket in project elasticsearch by elastic.

the class PercentilesBucketIT method testMetricTopLevelDefaultPercents.

public void testMetricTopLevelDefaultPercents() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("terms").field("tag").subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))).addAggregation(percentilesBucket("percentiles_bucket", "terms>sum")).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets.size(), equalTo(interval));
    double[] values = new double[interval];
    for (int i = 0; i < interval; ++i) {
        Terms.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat((String) bucket.getKey(), equalTo("tag" + (i % interval)));
        assertThat(bucket.getDocCount(), greaterThan(0L));
        Sum sum = bucket.getAggregations().get("sum");
        assertThat(sum, notNullValue());
        values[i] = sum.value();
    }
    Arrays.sort(values);
    PercentilesBucket percentilesBucketValue = response.getAggregations().get("percentiles_bucket");
    assertThat(percentilesBucketValue, notNullValue());
    assertThat(percentilesBucketValue.getName(), equalTo("percentiles_bucket"));
    assertPercentileBucket(values, percentilesBucketValue);
}
Also used : PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) PipelineAggregatorBuilders.percentilesBucket(org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.percentilesBucket) PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 10 with PercentilesBucket

use of org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket in project elasticsearch by elastic.

the class PercentilesBucketIT method testMetricAsSubAgg.

public void testMetricAsSubAgg() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("terms").field("tag").order(Terms.Order.term(true)).subAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).extendedBounds(minRandomValue, maxRandomValue).subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))).subAggregation(percentilesBucket("percentiles_bucket", "histo>sum").percents(PERCENTS))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    List<Terms.Bucket> termsBuckets = terms.getBuckets();
    assertThat(termsBuckets.size(), equalTo(interval));
    for (int i = 0; i < interval; ++i) {
        Terms.Bucket termsBucket = termsBuckets.get(i);
        assertThat(termsBucket, notNullValue());
        assertThat((String) termsBucket.getKey(), equalTo("tag" + (i % interval)));
        Histogram histo = termsBucket.getAggregations().get("histo");
        assertThat(histo, notNullValue());
        assertThat(histo.getName(), equalTo("histo"));
        List<? extends Histogram.Bucket> buckets = histo.getBuckets();
        List<Double> values = new ArrayList<>(numValueBuckets);
        for (int j = 0; j < numValueBuckets; ++j) {
            Histogram.Bucket bucket = buckets.get(j);
            assertThat(bucket, notNullValue());
            assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) j * interval));
            if (bucket.getDocCount() != 0) {
                Sum sum = bucket.getAggregations().get("sum");
                assertThat(sum, notNullValue());
                values.add(sum.value());
            }
        }
        Collections.sort(values);
        PercentilesBucket percentilesBucketValue = termsBucket.getAggregations().get("percentiles_bucket");
        assertThat(percentilesBucketValue, notNullValue());
        assertThat(percentilesBucketValue.getName(), equalTo("percentiles_bucket"));
        assertPercentileBucket(PERCENTS, values.stream().mapToDouble(Double::doubleValue).toArray(), percentilesBucketValue);
    }
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) ArrayList(java.util.ArrayList) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse) PipelineAggregatorBuilders.percentilesBucket(org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.percentilesBucket) PercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)10 PercentilesBucket (org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket)10 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)10 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)9 PipelineAggregatorBuilders.percentilesBucket (org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.percentilesBucket)9 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)6 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)4 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude)2 ArrayList (java.util.ArrayList)1