use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class TDigestPercentileRanksIT method testSingleValuedFieldOutsideRange.
public void testSingleValuedFieldOutsideRange() throws Exception {
final double[] pcts = new double[] { minValue - 1, maxValue + 1 };
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(randomCompression(percentileRanks("percentile_ranks")).field("value").values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValue, maxValue);
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class TDigestPercentileRanksIT method testSingleValuedField.
@Override
public void testSingleValuedField() throws Exception {
final double[] pcts = randomPercents(minValue, maxValue);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(randomCompression(percentileRanks("percentile_ranks")).field("value").values(pcts)).execute().actionGet();
assertHitCount(searchResponse, 10);
final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
assertConsistent(pcts, values, minValue, maxValue);
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class TDigestPercentileRanksIT method testSingleValuedFieldGetProperty.
@Override
public void testSingleValuedFieldGetProperty() throws Exception {
final double[] pcts = randomPercents(minValue, maxValue);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(randomCompression(percentileRanks("percentile_ranks")).field("value").values(pcts))).execute().actionGet();
assertHitCount(searchResponse, 10);
Global global = searchResponse.getAggregations().get("global");
assertThat(global, notNullValue());
assertThat(global.getName(), equalTo("global"));
assertThat(global.getDocCount(), equalTo(10L));
assertThat(global.getAggregations(), notNullValue());
assertThat(global.getAggregations().asMap().size(), equalTo(1));
PercentileRanks values = global.getAggregations().get("percentile_ranks");
assertThat(values, notNullValue());
assertThat(values.getName(), equalTo("percentile_ranks"));
assertThat(global.getProperty("percentile_ranks"), sameInstance(values));
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class HDRPercentileRanksAggregatorTests method testEmpty.
public void testEmpty() throws IOException {
PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg").field("field").method(PercentilesMethod.HDR).values(0.5);
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
fieldType.setName("field");
try (IndexReader reader = new MultiReader()) {
IndexSearcher searcher = new IndexSearcher(reader);
PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
Percentile rank = ranks.iterator().next();
assertEquals(Double.NaN, rank.getPercent(), 0d);
assertEquals(0.5, rank.getValue(), 0d);
}
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.
the class HDRPercentileRanksAggregatorTests method testSimple.
public void testSimple() throws IOException {
try (Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
for (double value : new double[] { 3, 0.2, 10 }) {
Document doc = new Document();
doc.add(new SortedNumericDocValuesField("field", NumericUtils.doubleToSortableLong(value)));
w.addDocument(doc);
}
PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg").field("field").method(PercentilesMethod.HDR).values(0.1, 0.5, 12);
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
fieldType.setName("field");
try (IndexReader reader = w.getReader()) {
IndexSearcher searcher = new IndexSearcher(reader);
PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
Iterator<Percentile> rankIterator = ranks.iterator();
Percentile rank = rankIterator.next();
assertEquals(0.1, rank.getValue(), 0d);
assertThat(rank.getPercent(), Matchers.equalTo(0d));
rank = rankIterator.next();
assertEquals(0.5, rank.getValue(), 0d);
assertThat(rank.getPercent(), Matchers.greaterThan(0d));
assertThat(rank.getPercent(), Matchers.lessThan(100d));
rank = rankIterator.next();
assertEquals(12, rank.getValue(), 0d);
assertThat(rank.getPercent(), Matchers.equalTo(100d));
assertFalse(rankIterator.hasNext());
}
}
}
Aggregations