Search in sources :

Example 31 with PercentileRanks

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));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 32 with PercentileRanks

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);
}
Also used : PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 33 with PercentileRanks

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);
}
Also used : Script(org.elasticsearch.script.Script) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 34 with PercentileRanks

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;
    }
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 35 with PercentileRanks

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);
}
Also used : Script(org.elasticsearch.script.Script) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

PercentileRanks (org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks)40 SearchResponse (org.elasticsearch.action.search.SearchResponse)36 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)36 Script (org.elasticsearch.script.Script)18 HashMap (java.util.HashMap)6 IndexReader (org.apache.lucene.index.IndexReader)4 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)4 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)4 Percentile (org.elasticsearch.search.aggregations.metrics.percentiles.Percentile)4 PercentileRanksAggregationBuilder (org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder)4 Document (org.apache.lucene.document.Document)2 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)2 MultiReader (org.apache.lucene.index.MultiReader)2 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)2 Directory (org.apache.lucene.store.Directory)2 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)2 Global (org.elasticsearch.search.aggregations.bucket.global.Global)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2