Search in sources :

Example 1 with Percentiles

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

the class MissingValueIT method testPercentiles.

public void testPercentiles() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(percentiles("percentiles").field("long").missing(1000)).get();
    assertSearchResponse(response);
    Percentiles percentiles = response.getAggregations().get("percentiles");
    assertEquals(1000, percentiles.percentile(100), 0);
}
Also used : Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with Percentiles

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

the class HDRPercentilesIT method testUnmapped.

@Override
public void testUnmapped() throws Exception {
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).field("value").percentiles(0, 10, 15, 100)).execute().actionGet();
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
    Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertThat(percentiles, notNullValue());
    assertThat(percentiles.getName(), equalTo("percentiles"));
    assertThat(percentiles.percentile(0), equalTo(Double.NaN));
    assertThat(percentiles.percentile(10), equalTo(Double.NaN));
    assertThat(percentiles.percentile(15), equalTo(Double.NaN));
    assertThat(percentiles.percentile(100), equalTo(Double.NaN));
}
Also used : Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 3 with Percentiles

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

the class HDRPercentilesIT 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(percentiles("percentiles").field("value").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).percentiles(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());
    Percentiles percentiles = bucket.getAggregations().get("percentiles");
    assertThat(percentiles, notNullValue());
    assertThat(percentiles.getName(), equalTo("percentiles"));
    assertThat(percentiles.percentile(10), equalTo(Double.NaN));
    assertThat(percentiles.percentile(15), equalTo(Double.NaN));
}
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 4 with Percentiles

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

the class HDRPercentilesIT method testMultiValuedFieldWithValueScriptWithParams.

@Override
public void testMultiValuedFieldWithValueScriptWithParams() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("dec", 1);
    final double[] pcts = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).field("values").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - dec", params)).percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, minValues - 1, maxValues - 1, sigDigits);
}
Also used : Script(org.elasticsearch.script.Script) HashMap(java.util.HashMap) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 5 with Percentiles

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

the class HDRPercentilesIT method testSingleValuedFieldWithValueScriptWithParams.

@Override
public void testSingleValuedFieldWithValueScriptWithParams() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("dec", 1);
    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 - dec", params)).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) HashMap(java.util.HashMap) 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