Search in sources :

Example 21 with Filter

use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.

the class TDigestPercentileRanksIT method testOrderByEmptyAggregation.

@Override
public void testOrderByEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(terms("terms").field("value").order(Terms.Order.compound(Terms.Order.aggregation("filter>ranks.99", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(percentileRanks("ranks").method(PercentilesMethod.TDIGEST).values(99).field("value")))).get();
    assertHitCount(searchResponse, 10);
    Terms terms = searchResponse.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets, notNullValue());
    assertThat(buckets.size(), equalTo(10));
    for (int i = 0; i < 10; i++) {
        Terms.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat(bucket.getKeyAsNumber(), equalTo((long) i + 1));
        assertThat(bucket.getDocCount(), equalTo(1L));
        Filter filter = bucket.getAggregations().get("filter");
        assertThat(filter, notNullValue());
        assertThat(filter.getDocCount(), equalTo(0L));
        PercentileRanks ranks = filter.getAggregations().get("ranks");
        assertThat(ranks, notNullValue());
        assertThat(ranks.percent(99), equalTo(Double.NaN));
    }
}
Also used : Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 22 with Filter

use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.

the class HDRPercentilesIT method testOrderByEmptyAggregation.

@Override
public void testOrderByEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(terms("terms").field("value").order(Terms.Order.compound(Terms.Order.aggregation("filter>percentiles.99", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(percentiles("percentiles").method(PercentilesMethod.HDR).field("value")))).get();
    assertHitCount(searchResponse, 10);
    Terms terms = searchResponse.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets, notNullValue());
    assertThat(buckets.size(), equalTo(10));
    for (int i = 0; i < 10; i++) {
        Terms.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat(bucket.getKeyAsNumber(), equalTo((long) i + 1));
        assertThat(bucket.getDocCount(), equalTo(1L));
        Filter filter = bucket.getAggregations().get("filter");
        assertThat(filter, notNullValue());
        assertThat(filter.getDocCount(), equalTo(0L));
        Percentiles percentiles = filter.getAggregations().get("percentiles");
        assertThat(percentiles, notNullValue());
        assertThat(percentiles.percentile(99), equalTo(Double.NaN));
    }
}
Also used : Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 23 with Filter

use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.

the class MaxIT method testOrderByEmptyAggregation.

@Override
public void testOrderByEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(terms("terms").field("value").order(Order.compound(Order.aggregation("filter>max", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(max("max").field("value")))).get();
    assertHitCount(searchResponse, 10);
    Terms terms = searchResponse.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets, notNullValue());
    assertThat(buckets.size(), equalTo(10));
    for (int i = 0; i < 10; i++) {
        Terms.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat(bucket.getKeyAsNumber(), equalTo((long) i + 1));
        assertThat(bucket.getDocCount(), equalTo(1L));
        Filter filter = bucket.getAggregations().get("filter");
        assertThat(filter, notNullValue());
        assertThat(filter.getDocCount(), equalTo(0L));
        Max max = filter.getAggregations().get("max");
        assertThat(max, notNullValue());
        assertThat(max.value(), equalTo(Double.NEGATIVE_INFINITY));
    }
}
Also used : Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Max(org.elasticsearch.search.aggregations.metrics.max.Max) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 24 with Filter

use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.

the class MinIT method testOrderByEmptyAggregation.

@Override
public void testOrderByEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(terms("terms").field("value").order(Order.compound(Order.aggregation("filter>min", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(min("min").field("value")))).get();
    assertHitCount(searchResponse, 10);
    Terms terms = searchResponse.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets, notNullValue());
    assertThat(buckets.size(), equalTo(10));
    for (int i = 0; i < 10; i++) {
        Terms.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat(bucket.getKeyAsNumber(), equalTo((long) i + 1));
        assertThat(bucket.getDocCount(), equalTo(1L));
        Filter filter = bucket.getAggregations().get("filter");
        assertThat(filter, notNullValue());
        assertThat(filter.getDocCount(), equalTo(0L));
        Min min = filter.getAggregations().get("min");
        assertThat(min, notNullValue());
        assertThat(min.value(), equalTo(Double.POSITIVE_INFINITY));
    }
}
Also used : Min(org.elasticsearch.search.aggregations.metrics.min.Min) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 25 with Filter

use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.

the class ExtendedStatsIT method testOrderByEmptyAggregation.

@Override
public void testOrderByEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(terms("terms").field("value").order(Order.compound(Order.aggregation("filter>extendedStats.avg", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(extendedStats("extendedStats").field("value")))).get();
    assertHitCount(searchResponse, 10);
    Terms terms = searchResponse.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    List<Terms.Bucket> buckets = terms.getBuckets();
    assertThat(buckets, notNullValue());
    assertThat(buckets.size(), equalTo(10));
    for (int i = 0; i < 10; i++) {
        Terms.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat(bucket.getKeyAsNumber(), equalTo((long) i + 1));
        assertThat(bucket.getDocCount(), equalTo(1L));
        Filter filter = bucket.getAggregations().get("filter");
        assertThat(filter, notNullValue());
        assertThat(filter.getDocCount(), equalTo(0L));
        ExtendedStats extendedStats = filter.getAggregations().get("extendedStats");
        assertThat(extendedStats, notNullValue());
        assertThat(extendedStats.getMin(), equalTo(Double.POSITIVE_INFINITY));
        assertThat(extendedStats.getMax(), equalTo(Double.NEGATIVE_INFINITY));
        assertThat(extendedStats.getAvg(), equalTo(Double.NaN));
        assertThat(extendedStats.getSum(), equalTo(0.0));
        assertThat(extendedStats.getCount(), equalTo(0L));
        assertThat(extendedStats.getStdDeviation(), equalTo(Double.NaN));
        assertThat(extendedStats.getSumOfSquares(), equalTo(0.0));
        assertThat(extendedStats.getVariance(), equalTo(Double.NaN));
        assertThat(extendedStats.getStdDeviationBound(Bounds.LOWER), equalTo(Double.NaN));
        assertThat(extendedStats.getStdDeviationBound(Bounds.UPPER), equalTo(Double.NaN));
    }
}
Also used : Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)43 SearchResponse (org.elasticsearch.action.search.SearchResponse)42 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)34 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)27 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)11 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)7 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)6 SearchRequest (org.elasticsearch.action.search.SearchRequest)5 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)5 Max (org.elasticsearch.search.aggregations.metrics.max.Max)5 ExtendedStats (org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats)5 ArrayList (java.util.ArrayList)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 QueryStringQueryBuilder (org.elasticsearch.index.query.QueryStringQueryBuilder)3 Global (org.elasticsearch.search.aggregations.bucket.global.Global)3 Nested (org.elasticsearch.search.aggregations.bucket.nested.Nested)3 Percentiles (org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles)3 Stats (org.elasticsearch.search.aggregations.metrics.stats.Stats)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 DateTime (org.joda.time.DateTime)3