@Override public void testSingleValuedFieldGetProperty() throws Exception { SearchResponse searchResponse = client() .prepareSearch("idx") .setQuery(matchAllQuery()) .addAggregation(global("global").subAggregation(avg("avg").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)); Avg avg = global.getAggregations().get("avg"); assertThat(avg, notNullValue()); assertThat(avg.getName(), equalTo("avg")); double expectedAvgValue = (double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10; assertThat(avg.getValue(), equalTo(expectedAvgValue)); assertThat((Avg) global.getProperty("avg"), equalTo(avg)); assertThat((double) global.getProperty("avg.value"), equalTo(expectedAvgValue)); assertThat((double) avg.getProperty("value"), equalTo(expectedAvgValue)); }
@Override @Test public void testSingleValuedField_getProperty() throws Exception { SearchResponse searchResponse = client() .prepareSearch("idx") .setQuery(matchAllQuery()) .addAggregation(global("global").subAggregation(max("max").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)); Max max = global.getAggregations().get("max"); assertThat(max, notNullValue()); assertThat(max.getName(), equalTo("max")); double expectedMaxValue = 10.0; assertThat(max.getValue(), equalTo(expectedMaxValue)); assertThat((Max) global.getProperty("max"), equalTo(max)); assertThat((double) global.getProperty("max.value"), equalTo(expectedMaxValue)); assertThat((double) max.getProperty("value"), equalTo(expectedMaxValue)); }
@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)); }
@Override public void testSingleValuedFieldGetProperty() throws Exception { SearchResponse searchResponse = client() .prepareSearch("idx") .setQuery(matchAllQuery()) .addAggregation(global("global").subAggregation(stats("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)); Stats stats = global.getAggregations().get("stats"); assertThat(stats, notNullValue()); assertThat(stats.getName(), equalTo("stats")); Stats statsFromProperty = (Stats) 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)); }