Search in sources :

Example 81 with Terms

use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.

the class TermsDocCountErrorIT method assertDocCountErrorWithinBounds.

private void assertDocCountErrorWithinBounds(int size, SearchResponse accurateResponse, SearchResponse testResponse) {
    Terms accurateTerms = accurateResponse.getAggregations().get("terms");
    assertThat(accurateTerms, notNullValue());
    assertThat(accurateTerms.getName(), equalTo("terms"));
    assertThat(accurateTerms.getDocCountError(), equalTo(0L));
    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(), greaterThanOrEqualTo(0L));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));
    assertThat(accurateTerms.getBuckets().size(), greaterThanOrEqualTo(testBuckets.size()));
    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        Terms.Bucket accurateBucket = accurateTerms.getBucketByKey(testBucket.getKeyAsString());
        assertThat(accurateBucket, notNullValue());
        assertThat(accurateBucket.getDocCountError(), equalTo(0L));
        assertThat(testBucket.getDocCountError(), lessThanOrEqualTo(testTerms.getDocCountError()));
        assertThat(testBucket.getDocCount() + testBucket.getDocCountError(), greaterThanOrEqualTo(accurateBucket.getDocCount()));
        assertThat(testBucket.getDocCount() - testBucket.getDocCountError(), lessThanOrEqualTo(accurateBucket.getDocCount()));
    }
    for (Terms.Bucket accurateBucket : accurateTerms.getBuckets()) {
        assertThat(accurateBucket, notNullValue());
        Terms.Bucket testBucket = accurateTerms.getBucketByKey(accurateBucket.getKeyAsString());
        if (testBucket == null) {
            assertThat(accurateBucket.getDocCount(), lessThanOrEqualTo(testTerms.getDocCountError()));
        }
    }
}
Also used : Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms)

Example 82 with Terms

use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.

the class TermsDocCountErrorIT method assertNoDocCountError.

private void assertNoDocCountError(int size, SearchResponse accurateResponse, SearchResponse testResponse) {
    Terms accurateTerms = accurateResponse.getAggregations().get("terms");
    assertThat(accurateTerms, notNullValue());
    assertThat(accurateTerms.getName(), equalTo("terms"));
    assertThat(accurateTerms.getDocCountError(), equalTo(0L));
    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(), equalTo(0L));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));
    assertThat(accurateTerms.getBuckets().size(), greaterThanOrEqualTo(testBuckets.size()));
    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        Terms.Bucket accurateBucket = accurateTerms.getBucketByKey(testBucket.getKeyAsString());
        assertThat(accurateBucket, notNullValue());
        assertThat(accurateBucket.getDocCountError(), equalTo(0L));
        assertThat(testBucket.getDocCountError(), equalTo(0L));
    }
}
Also used : Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms)

Example 83 with Terms

use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.

the class AvgIT 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>avg", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(avg("avg").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));
        Avg avg = filter.getAggregations().get("avg");
        assertThat(avg, notNullValue());
        assertThat(avg.value(), equalTo(Double.NaN));
    }
}
Also used : Avg(org.elasticsearch.search.aggregations.metrics.avg.Avg) 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 84 with Terms

use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.

the class HDRPercentileRanksIT 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.HDR).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 85 with Terms

use of org.elasticsearch.search.aggregations.bucket.terms.Terms in project elasticsearch by elastic.

the class StatsIT 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>stats.avg", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(stats("stats").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));
        Stats stats = filter.getAggregations().get("stats");
        assertThat(stats, notNullValue());
        assertThat(stats.getMin(), equalTo(Double.POSITIVE_INFINITY));
        assertThat(stats.getMax(), equalTo(Double.NEGATIVE_INFINITY));
        assertThat(stats.getAvg(), equalTo(Double.NaN));
        assertThat(stats.getSum(), equalTo(0.0));
        assertThat(stats.getCount(), equalTo(0L));
    }
}
Also used : Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Stats(org.elasticsearch.search.aggregations.metrics.stats.Stats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)252 SearchResponse (org.elasticsearch.action.search.SearchResponse)238 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)209 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)97 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)37 Bucket (org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket)36 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)30 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)26 Script (org.elasticsearch.script.Script)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)21 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude)16 ExtendedStats (org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats)16 SearchHits (org.elasticsearch.search.SearchHits)13 TopHits (org.elasticsearch.search.aggregations.metrics.tophits.TopHits)13 InternalBucketMetricValue (org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue)13 Avg (org.elasticsearch.search.aggregations.metrics.avg.Avg)12 StringTerms (org.elasticsearch.search.aggregations.bucket.terms.StringTerms)11 Sampler (org.elasticsearch.search.aggregations.bucket.sampler.Sampler)10 PipelineAggregatorBuilders.percentilesBucket (org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.percentilesBucket)9