Merge pull request #17264 from pjo256/master

Setting 'other' bucket on empty aggregation
This commit is contained in:
Colin Goodheart-Smithe 2016-03-23 09:19:42 +00:00
commit b8ac05149d
2 changed files with 28 additions and 0 deletions

View File

@ -194,6 +194,12 @@ public class FiltersAggregator extends BucketsAggregator {
InternalFilters.InternalBucket bucket = new InternalFilters.InternalBucket(keys[i], 0, subAggs, keyed); InternalFilters.InternalBucket bucket = new InternalFilters.InternalBucket(keys[i], 0, subAggs, keyed);
buckets.add(bucket); buckets.add(bucket);
} }
if (showOtherBucket) {
InternalFilters.InternalBucket bucket = new InternalFilters.InternalBucket(otherBucketKey, 0, subAggs, keyed);
buckets.add(bucket);
}
return new InternalFilters(name, buckets, keyed, pipelineAggregators(), metaData()); return new InternalFilters(name, buckets, keyed, pipelineAggregators(), metaData());
} }

View File

@ -435,4 +435,26 @@ public class FiltersIT extends ESIntegTestCase {
assertThat((double) propertiesCounts[2], equalTo((double) sum / numOtherDocs)); assertThat((double) propertiesCounts[2], equalTo((double) sum / numOtherDocs));
} }
public void testEmptyAggregationWithOtherBucket() throws Exception {
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery())
.addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0)
.subAggregation(filters("filters", new KeyedFilter("foo", matchAllQuery())).otherBucket(true).otherBucketKey("bar")))
.execute().actionGet();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
Histogram histo = searchResponse.getAggregations().get("histo");
assertThat(histo, Matchers.notNullValue());
Histogram.Bucket bucket = histo.getBuckets().get(1);
assertThat(bucket, Matchers.notNullValue());
Filters filters = bucket.getAggregations().get("filters");
assertThat(filters, notNullValue());
Filters.Bucket other = filters.getBucketByKey("bar");
assertThat(other, Matchers.notNullValue());
assertThat(other.getKeyAsString(), equalTo("bar"));
assertThat(other.getDocCount(), is(0L));
}
} }