use of org.elasticsearch.search.aggregations.bucket.filter.Filter 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));
}
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter 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));
}
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter 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));
}
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.
the class TDigestPercentilesIT 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.TDIGEST).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));
}
}
use of org.elasticsearch.search.aggregations.bucket.filter.Filter in project elasticsearch by elastic.
the class SumIT 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>sum", true))).subAggregation(filter("filter", termQuery("value", 100)).subAggregation(sum("sum").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));
Sum sum = filter.getAggregations().get("sum");
assertThat(sum, notNullValue());
assertThat(sum.value(), equalTo(0.0));
}
}
Aggregations