Search in sources :

Example 11 with Percentiles

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

the class TDigestPercentilesIT method testMultiValuedField.

@Override
public void testMultiValuedField() throws Exception {
    final double[] pcts = randomPercentiles();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(randomCompression(percentiles("percentiles")).field("values").percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, minValues, maxValues);
}
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 12 with Percentiles

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

the class TDigestPercentilesIT 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();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(randomCompression(percentiles("percentiles")).script(script).percentiles(pcts)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    final Percentiles percentiles = searchResponse.getAggregations().get("percentiles");
    assertConsistent(pcts, percentiles, minValue - 1, maxValue - 1);
}
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 13 with Percentiles

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

the class TDigestPercentilesIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    final double[] pcts = randomPercentiles();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(randomCompression(percentiles("percentiles")).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 14 with Percentiles

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

the class TDigestPercentilesIT method testUnmapped.

@Override
public void testUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(randomCompression(percentiles("percentiles")).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 15 with Percentiles

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

the class TDigestPercentilesIT method testMultiValuedFieldWithValueScriptReverse.

public void testMultiValuedFieldWithValueScriptReverse() throws Exception {
    final double[] pcts = randomPercentiles();
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(randomCompression(percentiles("percentiles")).field("values").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, -maxValues, -minValues);
}
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