Search in sources :

Example 21 with PercentileRanks

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

the class TDigestPercentileRanksIT method testSingleValuedFieldPartiallyUnmapped.

@Override
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
    final double[] pcts = randomPercents(minValue, maxValue);
    SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped").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);
}
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 22 with PercentileRanks

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

the class TDigestPercentileRanksIT method testMultiValuedFieldWithValueScriptReverse.

public void testMultiValuedFieldWithValueScriptReverse() throws Exception {
    final double[] pcts = randomPercents(-maxValues, -minValues);
    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, -maxValues, -minValues);
}
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 23 with PercentileRanks

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

the class TDigestPercentileRanksIT method testScriptSingleValuedWithParams.

@Override
public void testScriptSingleValuedWithParams() throws Exception {
    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(randomCompression(percentileRanks("percentile_ranks")).script(script).values(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final PercentileRanks values = searchResponse.getAggregations().get("percentile_ranks");
    assertConsistent(pcts, values, minValue - 1, maxValue - 1);
}
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)

Example 24 with PercentileRanks

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

the class TDigestPercentileRanksIT method testOrderBySubAggregation.

public void testOrderBySubAggregation() {
    boolean asc = randomBoolean();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(histogram("histo").field("value").interval(2L).subAggregation(randomCompression(percentileRanks("percentile_ranks").field("value").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 25 with PercentileRanks

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

the class TDigestPercentileRanksIT method testMultiValuedFieldWithValueScriptWithParams.

@Override
public void testMultiValuedFieldWithValueScriptWithParams() throws Exception {
    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(randomCompression(percentileRanks("percentile_ranks")).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);
}
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