use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testEmptyAggregation.
@Override
public void testEmptyAggregation() throws Exception {
int sigDigits = randomSignificantDigits();
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx").setQuery(matchAllQuery()).addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0).subAggregation(percentileRanks("percentile_ranks").field("value").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).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 testSingleValuedFieldOutsideRange.
public void testSingleValuedFieldOutsideRange() throws Exception {
int sigDigits = randomSignificantDigits();
final double[] pcts = new double[] { minValue - 1, maxValue + 1 };
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).field("value").values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValue, maxValue, sigDigits);
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testMultiValuedFieldWithValueScriptReverse.
public void testMultiValuedFieldWithValueScriptReverse() throws Exception {
int sigDigits = randomSignificantDigits();
final double[] pcts = randomPercents(20 - maxValues, 20 - minValues);
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, "20 - _value", emptyMap())).values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, 20 - maxValues, 20 - minValues, sigDigits);
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testOrderBySubAggregation.
public void testOrderBySubAggregation() {
int sigDigits = randomSignificantDigits();
boolean asc = randomBoolean();
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(histogram("histo").field("value").interval(2L).subAggregation(percentileRanks("percentile_ranks").field("value").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).values(99)).order(Order.aggregation("percentile_ranks", "99", asc))).execute().actionGet();
assertHitCount(searchResponse, 10);
Histogram histo = searchResponse.getAggregations().get("histo");
double previous = asc ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
for (Histogram.Bucket bucket : histo.getBuckets()) {
PercentileRanks values = bucket.getAggregations().get("percentile_ranks");
double p99 = values.percent(99);
if (asc) {
assertThat(p99, greaterThanOrEqualTo(previous));
} else {
assertThat(p99, lessThanOrEqualTo(previous));
}
previous = p99;
}
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class HDRPercentileRanksIT method testMultiValuedFieldWithValueScript.
@Override
public void testMultiValuedFieldWithValueScript() throws Exception {
int sigDigits = randomSignificantDigits();
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 - 1", emptyMap())).values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValues - 1, maxValues - 1, sigDigits);
}
Aggregations