Search in sources :

Example 6 with Missing

use of org.elasticsearch.search.aggregations.bucket.missing.Missing in project elasticsearch by elastic.

the class ExtendedStatsIT method testEmptySubAggregation.

public void testEmptySubAggregation() {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(terms("value").field("value").subAggregation(missing("values").field("values").subAggregation(extendedStats("stats").field("value")))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Terms terms = searchResponse.getAggregations().get("value");
    assertThat(terms, notNullValue());
    assertThat(terms.getBuckets().size(), equalTo(10));
    for (Terms.Bucket bucket : terms.getBuckets()) {
        assertThat(bucket.getDocCount(), equalTo(1L));
        Missing missing = bucket.getAggregations().get("values");
        assertThat(missing, notNullValue());
        assertThat(missing.getDocCount(), equalTo(0L));
        ExtendedStats stats = missing.getAggregations().get("stats");
        assertThat(stats, notNullValue());
        assertThat(stats.getName(), equalTo("stats"));
        assertThat(stats.getSumOfSquares(), equalTo(0.0));
        assertThat(stats.getCount(), equalTo(0L));
        assertThat(stats.getSum(), equalTo(0.0));
        assertThat(stats.getMin(), equalTo(Double.POSITIVE_INFINITY));
        assertThat(stats.getMax(), equalTo(Double.NEGATIVE_INFINITY));
        assertThat(Double.isNaN(stats.getStdDeviation()), is(true));
        assertThat(Double.isNaN(stats.getAvg()), is(true));
        assertThat(Double.isNaN(stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER)), is(true));
        assertThat(Double.isNaN(stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER)), is(true));
    }
}
Also used : Missing(org.elasticsearch.search.aggregations.bucket.missing.Missing) 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)

Example 7 with Missing

use of org.elasticsearch.search.aggregations.bucket.missing.Missing in project elasticsearch by elastic.

the class MissingIT method testPartiallyUnmapped.

public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx", "unmapped_idx").addAggregation(missing("missing_tag").field("tag")).execute().actionGet();
    assertSearchResponse(response);
    Missing missing = response.getAggregations().get("missing_tag");
    assertThat(missing, notNullValue());
    assertThat(missing.getName(), equalTo("missing_tag"));
    assertThat(missing.getDocCount(), equalTo((long) numDocsMissing + numDocsUnmapped));
}
Also used : Missing(org.elasticsearch.search.aggregations.bucket.missing.Missing) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 8 with Missing

use of org.elasticsearch.search.aggregations.bucket.missing.Missing in project elasticsearch by elastic.

the class MissingIT method testUnmapped.

public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("unmapped_idx").addAggregation(missing("missing_tag").field("tag")).execute().actionGet();
    assertSearchResponse(response);
    Missing missing = response.getAggregations().get("missing_tag");
    assertThat(missing, notNullValue());
    assertThat(missing.getName(), equalTo("missing_tag"));
    assertThat(missing.getDocCount(), equalTo((long) numDocsUnmapped));
}
Also used : Missing(org.elasticsearch.search.aggregations.bucket.missing.Missing) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 9 with Missing

use of org.elasticsearch.search.aggregations.bucket.missing.Missing in project elasticsearch by elastic.

the class ShardReduceIT method testGlobalWithFilterWithMissing.

public void testGlobalWithFilterWithMissing() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(global("global").subAggregation(filter("filter", QueryBuilders.matchAllQuery()).subAggregation(missing("missing").field("foobar").subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))))).execute().actionGet();
    assertSearchResponse(response);
    Global global = response.getAggregations().get("global");
    Filter filter = global.getAggregations().get("filter");
    Missing missing = filter.getAggregations().get("missing");
    Histogram histo = missing.getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
Also used : Missing(org.elasticsearch.search.aggregations.bucket.missing.Missing) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)9 Missing (org.elasticsearch.search.aggregations.bucket.missing.Missing)9 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)9 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)3 AggregationBuilders.dateHistogram (org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntIntMap (com.carrotsearch.hppc.IntIntMap)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 SubAggCollectionMode (org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode)1 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)1 Global (org.elasticsearch.search.aggregations.bucket.global.Global)1 Avg (org.elasticsearch.search.aggregations.metrics.avg.Avg)1 ExtendedStats (org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats)1