Search in sources :

Example 6 with ExtendedStats

use of org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats in project elasticsearch by elastic.

the class ExtendedStatsIT method testScriptSingleValued.

@Override
public void testScriptSingleValued() throws Exception {
    double sigma = randomDouble() * randomIntBetween(1, 10);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(extendedStats("stats").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['value'].value", Collections.emptyMap())).sigma(sigma)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    ExtendedStats stats = searchResponse.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    assertThat(stats.getAvg(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10));
    assertThat(stats.getMin(), equalTo(1.0));
    assertThat(stats.getMax(), equalTo(10.0));
    assertThat(stats.getSum(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10));
    assertThat(stats.getCount(), equalTo(10L));
    assertThat(stats.getSumOfSquares(), equalTo((double) 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100));
    assertThat(stats.getVariance(), equalTo(variance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
    assertThat(stats.getStdDeviation(), equalTo(stdDev(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
    checkUpperLowerBounds(stats, sigma);
}
Also used : Script(org.elasticsearch.script.Script) ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 7 with ExtendedStats

use of org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats in project elasticsearch by elastic.

the class ExtendedStatsIT method testSingleValuedFieldWithValueScript.

@Override
public void testSingleValuedFieldWithValueScript() throws Exception {
    double sigma = randomDouble() * randomIntBetween(1, 10);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(extendedStats("stats").field("value").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value + 1", Collections.emptyMap())).sigma(sigma)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    ExtendedStats stats = searchResponse.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    assertThat(stats.getAvg(), equalTo((double) (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11) / 10));
    assertThat(stats.getMin(), equalTo(2.0));
    assertThat(stats.getMax(), equalTo(11.0));
    assertThat(stats.getSum(), equalTo((double) 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11));
    assertThat(stats.getCount(), equalTo(10L));
    assertThat(stats.getSumOfSquares(), equalTo((double) 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 121));
    assertThat(stats.getVariance(), equalTo(variance(2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
    assertThat(stats.getStdDeviation(), equalTo(stdDev(2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
    checkUpperLowerBounds(stats, sigma);
}
Also used : Script(org.elasticsearch.script.Script) ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 8 with ExtendedStats

use of org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats in project elasticsearch by elastic.

the class ExtendedStatsIT method testScriptMultiValued.

@Override
public void testScriptMultiValued() throws Exception {
    double sigma = randomDouble() * randomIntBetween(1, 10);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(extendedStats("stats").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "doc['values'].values", Collections.emptyMap())).sigma(sigma)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    ExtendedStats stats = searchResponse.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    assertThat(stats.getAvg(), equalTo((double) (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12) / 20));
    assertThat(stats.getMin(), equalTo(2.0));
    assertThat(stats.getMax(), equalTo(12.0));
    assertThat(stats.getSum(), equalTo((double) 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12));
    assertThat(stats.getCount(), equalTo(20L));
    assertThat(stats.getSumOfSquares(), equalTo((double) 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 121 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 121 + 144));
    assertThat(stats.getVariance(), equalTo(variance(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)));
    assertThat(stats.getStdDeviation(), equalTo(stdDev(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)));
    checkUpperLowerBounds(stats, sigma);
}
Also used : Script(org.elasticsearch.script.Script) ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 9 with ExtendedStats

use of org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats in project elasticsearch by elastic.

the class ExtendedStatsIT method testMultiValuedField.

@Override
public void testMultiValuedField() throws Exception {
    double sigma = randomDouble() * randomIntBetween(1, 10);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(extendedStats("stats").field("values").sigma(sigma)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    ExtendedStats stats = searchResponse.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    assertThat(stats.getAvg(), equalTo((double) (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12) / 20));
    assertThat(stats.getMin(), equalTo(2.0));
    assertThat(stats.getMax(), equalTo(12.0));
    assertThat(stats.getSum(), equalTo((double) 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12));
    assertThat(stats.getCount(), equalTo(20L));
    assertThat(stats.getSumOfSquares(), equalTo((double) 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 121 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 121 + 144));
    assertThat(stats.getVariance(), equalTo(variance(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)));
    assertThat(stats.getStdDeviation(), equalTo(stdDev(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)));
    checkUpperLowerBounds(stats, sigma);
}
Also used : ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 10 with ExtendedStats

use of org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats in project elasticsearch by elastic.

the class ExtendedStatsIT method testMultiValuedFieldWithValueScript.

@Override
public void testMultiValuedFieldWithValueScript() throws Exception {
    double sigma = randomDouble() * randomIntBetween(1, 10);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(extendedStats("stats").field("values").script(new Script(ScriptType.INLINE, AggregationTestScriptsPlugin.NAME, "_value - 1", Collections.emptyMap())).sigma(sigma)).execute().actionGet();
    assertHitCount(searchResponse, 10);
    ExtendedStats stats = searchResponse.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    assertThat(stats.getAvg(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11) / 20));
    assertThat(stats.getMin(), equalTo(1.0));
    assertThat(stats.getMax(), equalTo(11.0));
    assertThat(stats.getSum(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11));
    assertThat(stats.getCount(), equalTo(20L));
    assertThat(stats.getSumOfSquares(), equalTo((double) 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 121));
    assertThat(stats.getVariance(), equalTo(variance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
    assertThat(stats.getStdDeviation(), equalTo(stdDev(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
    checkUpperLowerBounds(stats, sigma);
}
Also used : Script(org.elasticsearch.script.Script) ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

ExtendedStats (org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats)24 SearchResponse (org.elasticsearch.action.search.SearchResponse)23 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)22 Script (org.elasticsearch.script.Script)8 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)7 HashMap (java.util.HashMap)4 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)4 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)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 TimeValue (org.elasticsearch.common.unit.TimeValue)1