Search in sources :

Example 26 with Percentiles

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

the class HDRPercentilesIT method testScriptSingleValued.

@Override
public void testScriptSingleValued() throws Exception {
    final double[] pcts = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", emptyMap())).percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, minValue, maxValue, sigDigits);
}
Also used : Script(org.elasticsearch.script.Script) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 27 with Percentiles

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

the class HDRPercentilesIT 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(percentiles("percentiles").field("value").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits).percentiles(99)).order(Order.aggregation("percentiles", "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()) {
        Percentiles percentiles = bucket.getAggregations().get("percentiles");
        double p99 = percentiles.percentile(99);
        if (asc) {
            assertThat(p99, greaterThanOrEqualTo(previous));
        } else {
            assertThat(p99, lessThanOrEqualTo(previous));
        }
        previous = p99;
    }
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 28 with Percentiles

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

the class HDRPercentilesIT method testSingleValuedFieldWithValueScript.

@Override
public void testSingleValuedFieldWithValueScript() throws Exception {
    final double[] pcts = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).field("value").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", emptyMap())).percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, minValue - 1, maxValue - 1, sigDigits);
}
Also used : Script(org.elasticsearch.script.Script) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 29 with Percentiles

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

the class HDRPercentilesIT method testScriptMultiValued.

@Override
public void testScriptMultiValued() throws Exception {
    final double[] pcts = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    Script script = new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", emptyMap());
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).script(script).percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, minValues, maxValues, sigDigits);
}
Also used : Script(org.elasticsearch.script.Script) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 30 with Percentiles

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

the class HDRPercentilesIT method testSingleValuedFieldPartiallyUnmapped.

@Override
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
    final double[] pcts = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped").setQuery(matchAllQuery()).addAggregation(percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).field("value").percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, minValue, maxValue, sigDigits);
}
Also used : Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)36 Percentiles (org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles)36 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)35 Script (org.elasticsearch.script.Script)18 HashMap (java.util.HashMap)6 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)4 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)3 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)3 Global (org.elasticsearch.search.aggregations.bucket.global.Global)2 AuthorisationException (com.atlassian.stash.exception.AuthorisationException)1 Repository (com.atlassian.stash.repository.Repository)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 GlobalSettings (com.palantir.stash.codesearch.admin.GlobalSettings)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)1