Search in sources :

Example 1 with PercentileRanks

use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.

the class HDRPercentileRanksIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    int sigDigits = randomSignificantDigits();
    final double[] pcts = randomPercents(minValue, maxValue);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).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));
}
Also used : PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with PercentileRanks

use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.

the class HDRPercentileRanksIT method testUnmapped.

@Override
public void testUnmapped() throws Exception {
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).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));
}
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 3 with PercentileRanks

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

Example 4 with PercentileRanks

use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.

the class HDRPercentileRanksIT method testScriptMultiValued.

@Override
public void testScriptMultiValued() throws Exception {
    int sigDigits = randomSignificantDigits();
    final double[] pcts = randomPercents(minValues, maxValues);
    Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).script(script).values(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
    assertConsistent(pcts, values, minValues, maxValues, 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 5 with PercentileRanks

use of org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks in project elasticsearch by elastic.

the class HDRPercentileRanksIT method testScriptSingleValuedWithParams.

@Override
public void testScriptSingleValuedWithParams() throws Exception {
    int sigDigits = randomSignificantDigits();
    Map<String, Object> params = new HashMap<>();
    params.put("dec", 1);
    Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value - dec", params);
    final double[] pcts = randomPercents(minValue - 1, maxValue - 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).script(script).values(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
    assertConsistent(pcts, values, minValue - 1, maxValue - 1, sigDigits);
}
Also used : Script(org.elasticsearch.script.Script) HashMap(java.util.HashMap) 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