Search in sources :

Example 11 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class SumIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(sum("sum").field("value"))).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));
    Sum sum = global.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    double expectedSumValue = (double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
    assertThat(sum.getValue(), equalTo(expectedSumValue));
    assertThat((Sum) global.getProperty("sum"), equalTo(sum));
    assertThat((double) global.getProperty("sum.value"), equalTo(expectedSumValue));
    assertThat((double) sum.getProperty("value"), equalTo(expectedSumValue));
}
Also used : Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 12 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class ValueCountIT method testSingleValuedFieldGetProperty.

public void testSingleValuedFieldGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(count("count").field("value"))).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));
    ValueCount valueCount = global.getAggregations().get("count");
    assertThat(valueCount, notNullValue());
    assertThat(valueCount.getName(), equalTo("count"));
    assertThat(valueCount.getValue(), equalTo(10L));
    assertThat((ValueCount) global.getProperty("count"), equalTo(valueCount));
    assertThat((double) global.getProperty("count.value"), equalTo(10d));
    assertThat((double) valueCount.getProperty("value"), equalTo(10d));
}
Also used : ValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 13 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class CardinalityIT method testSingleValuedNumericGetProperty.

public void testSingleValuedNumericGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))).execute().actionGet();
    assertSearchResponse(searchResponse);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    // assertThat(global.getDocCount(), equalTo(numDocs));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    Cardinality cardinality = global.getAggregations().get("cardinality");
    assertThat(cardinality, notNullValue());
    assertThat(cardinality.getName(), equalTo("cardinality"));
    long expectedValue = numDocs;
    assertCount(cardinality, expectedValue);
    assertThat((Cardinality) global.getProperty("cardinality"), equalTo(cardinality));
    assertThat((double) global.getProperty("cardinality.value"), equalTo((double) cardinality.getValue()));
    assertThat((double) cardinality.getProperty("value"), equalTo((double) cardinality.getValue()));
}
Also used : Cardinality(org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality) 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 Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class ExtendedStatsIT method testSingleValuedFieldGetProperty.

@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(extendedStats("stats").field("value"))).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));
    ExtendedStats stats = global.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    ExtendedStats statsFromProperty = (ExtendedStats) global.getProperty("stats");
    assertThat(statsFromProperty, notNullValue());
    assertThat(statsFromProperty, sameInstance(stats));
    double expectedAvgValue = (double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10;
    assertThat(stats.getAvg(), equalTo(expectedAvgValue));
    assertThat((double) global.getProperty("stats.avg"), equalTo(expectedAvgValue));
    double expectedMinValue = 1.0;
    assertThat(stats.getMin(), equalTo(expectedMinValue));
    assertThat((double) global.getProperty("stats.min"), equalTo(expectedMinValue));
    double expectedMaxValue = 10.0;
    assertThat(stats.getMax(), equalTo(expectedMaxValue));
    assertThat((double) global.getProperty("stats.max"), equalTo(expectedMaxValue));
    double expectedSumValue = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
    assertThat(stats.getSum(), equalTo(expectedSumValue));
    assertThat((double) global.getProperty("stats.sum"), equalTo(expectedSumValue));
    long expectedCountValue = 10;
    assertThat(stats.getCount(), equalTo(expectedCountValue));
    assertThat((double) global.getProperty("stats.count"), equalTo((double) expectedCountValue));
    double expectedSumOfSquaresValue = (double) 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100;
    assertThat(stats.getSumOfSquares(), equalTo(expectedSumOfSquaresValue));
    assertThat((double) global.getProperty("stats.sum_of_squares"), equalTo(expectedSumOfSquaresValue));
    double expectedVarianceValue = variance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    assertThat(stats.getVariance(), equalTo(expectedVarianceValue));
    assertThat((double) global.getProperty("stats.variance"), equalTo(expectedVarianceValue));
    double expectedStdDevValue = stdDev(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    assertThat(stats.getStdDeviation(), equalTo(expectedStdDevValue));
    assertThat((double) global.getProperty("stats.std_deviation"), equalTo(expectedStdDevValue));
}
Also used : ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 15 with Global

use of org.elasticsearch.search.aggregations.bucket.global.Global in project elasticsearch by elastic.

the class GeoBoundsIT method testSingleValuedField_getProperty.

public void testSingleValuedField_getProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch(IDX_NAME).setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false))).execute().actionGet();
    assertSearchResponse(searchResponse);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo((long) numDocs));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    GeoBounds geobounds = global.getAggregations().get(aggName);
    assertThat(geobounds, notNullValue());
    assertThat(geobounds.getName(), equalTo(aggName));
    assertThat((GeoBounds) global.getProperty(aggName), sameInstance(geobounds));
    GeoPoint topLeft = geobounds.topLeft();
    GeoPoint bottomRight = geobounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".top"), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".left"), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".bottom"), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat((double) global.getProperty(aggName + ".right"), closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) Global(org.elasticsearch.search.aggregations.bucket.global.Global) GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)23 Global (org.elasticsearch.search.aggregations.bucket.global.Global)23 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)20 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)3 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)3 GeoPoint (org.elasticsearch.common.geo.GeoPoint)2 AggregationBuilders.dateHistogram (org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram)2 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)2 PercentileRanks (org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks)2 Percentiles (org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles)2 Stats (org.elasticsearch.search.aggregations.metrics.stats.Stats)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 Script (org.elasticsearch.script.Script)1 GlobalBuilder (org.elasticsearch.search.aggregations.bucket.global.GlobalBuilder)1 Missing (org.elasticsearch.search.aggregations.bucket.missing.Missing)1 TermsBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder)1