Search in sources :

Example 21 with Avg

use of org.elasticsearch.search.aggregations.metrics.avg.Avg in project elasticsearch by elastic.

the class AvgIT method testMultiValuedField.

@Override
public void testMultiValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").field("values")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12) / 20));
}
Also used : Avg(org.elasticsearch.search.aggregations.metrics.avg.Avg) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 22 with Avg

use of org.elasticsearch.search.aggregations.metrics.avg.Avg in project elasticsearch by elastic.

the class AvgIT method testScriptSingleValuedWithParams.

@Override
public void testScriptSingleValuedWithParams() throws Exception {
    Map<String, Object> params = Collections.singletonMap("inc", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "value", params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11) / 10));
}
Also used : LeafSearchScript(org.elasticsearch.script.LeafSearchScript) SearchScript(org.elasticsearch.script.SearchScript) Script(org.elasticsearch.script.Script) CompiledScript(org.elasticsearch.script.CompiledScript) ExecutableScript(org.elasticsearch.script.ExecutableScript) Avg(org.elasticsearch.search.aggregations.metrics.avg.Avg) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 23 with Avg

use of org.elasticsearch.search.aggregations.metrics.avg.Avg in project elasticsearch by elastic.

the class AvgIT method testSingleValuedFieldPartiallyUnmapped.

@Override
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped").setQuery(matchAllQuery()).addAggregation(avg("avg").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10));
}
Also used : Avg(org.elasticsearch.search.aggregations.metrics.avg.Avg) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 24 with Avg

use of org.elasticsearch.search.aggregations.metrics.avg.Avg in project elasticsearch by elastic.

the class AvgIT method testUnmapped.

@Override
public void testUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(avg("avg").field("value")).execute().actionGet();
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo(Double.NaN));
}
Also used : Avg(org.elasticsearch.search.aggregations.metrics.avg.Avg) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 25 with Avg

use of org.elasticsearch.search.aggregations.metrics.avg.Avg in project elasticsearch by elastic.

the class AvgIT method testScriptMultiValued.

@Override
public void testScriptMultiValued() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").script(new Script(ScriptType.INLINE, ExtractFieldScriptEngine.NAME, "values", Collections.emptyMap()))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12) / 20));
}
Also used : LeafSearchScript(org.elasticsearch.script.LeafSearchScript) SearchScript(org.elasticsearch.script.SearchScript) Script(org.elasticsearch.script.Script) CompiledScript(org.elasticsearch.script.CompiledScript) ExecutableScript(org.elasticsearch.script.ExecutableScript) Avg(org.elasticsearch.search.aggregations.metrics.avg.Avg) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)34 Avg (org.elasticsearch.search.aggregations.metrics.avg.Avg)34 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)34 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)12 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)11 CompiledScript (org.elasticsearch.script.CompiledScript)8 ExecutableScript (org.elasticsearch.script.ExecutableScript)8 LeafSearchScript (org.elasticsearch.script.LeafSearchScript)8 Script (org.elasticsearch.script.Script)8 SearchScript (org.elasticsearch.script.SearchScript)8 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)3 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)3 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)2 Filters (org.elasticsearch.search.aggregations.bucket.filters.Filters)2 KeyedFilter (org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter)2 Bucket (org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket)2 PipelineAggregatorBuilders.movingAvg (org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.movingAvg)2 SimpleValue (org.elasticsearch.search.aggregations.pipeline.SimpleValue)2 SimpleModel (org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1