Search in sources :

Example 31 with Percentiles

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

the class HDRPercentilesIT method testMultiValuedFieldWithValueScriptReverse.

public void testMultiValuedFieldWithValueScriptReverse() 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("values").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "20 - _value", emptyMap())).percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, 20 - maxValues, 20 - minValues, 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 32 with Percentiles

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

the class HDRPercentilesIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    final double[] pcts = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(percentiles("percentiles").numberOfSignificantValueDigits(sigDigits).method(PercentilesMethod.HDR).field("value").percentiles(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));
    Percentiles percentiles = global.getAggregations().get("percentiles");
    assertThat(percentiles, notNullValue());
    assertThat(percentiles.getName(), equalTo("percentiles"));
    assertThat(global.getProperty("percentiles"), sameInstance(percentiles));
}
Also used : Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 33 with Percentiles

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

the class HDRPercentilesIT 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 = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    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, 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)

Example 34 with Percentiles

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

the class HDRPercentilesIT method testSingleValuedField.

@Override
public void testSingleValuedField() throws Exception {
    final double[] pcts = randomPercentiles();
    int sigDigits = randomIntBetween(1, 5);
    SearchResponse searchResponse = client().prepareSearch("idx").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)

Example 35 with Percentiles

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

the class HDRPercentilesIT method testScriptMultiValuedWithParams.

@Override
public void testScriptMultiValuedWithParams() throws Exception {
    Script script = AggregationTestScriptsPlugin.DECREMENT_ALL_VALUES;
    final double[] pcts = randomPercentiles();
    int sigDigits = randomSignificantDigits();
    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 - 1, maxValues - 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)

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