use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class TDigestPercentileRanksIT method testUnmapped.
@Override
public void testUnmapped() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(randomCompression(percentileRanks("percentile_ranks")).field("value").values(0, 10, 15, 100)).execute().actionGet();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
PercentileRanks reversePercentiles = searchResponse.getAggregations().get("percentile_ranks");
assertThat(reversePercentiles, notNullValue());
assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
assertThat(reversePercentiles.percent(0), equalTo(Double.NaN));
assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
assertThat(reversePercentiles.percent(100), equalTo(Double.NaN));
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class TDigestPercentileRanksIT method testMultiValuedFieldWithValueScript.
@Override
public void testMultiValuedFieldWithValueScript() throws Exception {
final double[] pcts = randomPercents(minValues - 1, maxValues - 1);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(randomCompression(percentileRanks("percentile_ranks")).field("values").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())).values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValues - 1, maxValues - 1);
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks 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));
}
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class TDigestPercentileRanksIT method testEmptyAggregation.
@Override
public void testEmptyAggregation() throws Exception {
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx").setQuery(matchAllQuery()).addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0).subAggregation(randomCompression(percentileRanks("percentile_ranks").field("value")).values(10, 15))).execute().actionGet();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
Histogram histo = searchResponse.getAggregations().get("histo");
assertThat(histo, notNullValue());
Histogram.Bucket bucket = histo.getBuckets().get(1);
assertThat(bucket, notNullValue());
PercentileRanks reversePercentiles = bucket.getAggregations().get("percentile_ranks");
assertThat(reversePercentiles, notNullValue());
assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testMultiValuedFieldWithValueScriptWithParams.
@Override
public void testMultiValuedFieldWithValueScriptWithParams() throws Exception {
int sigDigits = randomSignificantDigits();
Map<String, Object> params = new HashMap<>();
params.put("dec", 1);
final double[] pcts = randomPercents(minValues - 1, maxValues - 1);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).field("values").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params)).values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValues - 1, maxValues - 1, sigDigits);
}
Aggregations