ElasticResponse { public Map<String,ElasticAggregation> getAggregations() { return aggregations; }  ElasticResults getResults(); Map<String,ElasticAggregation> getAggregations(); String getScrollId(); @JsonIgnore List<ElasticHit> getHits(); int getNumHits(); long getTotalNumHits(); float getMaxScore(); @Override String toString();  }
@Test public void testMissingAggregation() throws IOException { ElasticResponse response = mapper.readValue("{}", ElasticResponse.class); assertNull(response.getAggregations()); }
@Test public void testAggregations() throws IOException { String content = "{\"aggregations\":{\"first\":{\"buckets\": [{\"key\":\"0\",\"doc_count\":10}]}}}"; ElasticResponse response = mapper.readValue(content, ElasticResponse.class); assertEquals(1, response.getAggregations().size()); assertEquals(1, response.getAggregations().size()); ElasticAggregation aggregations = response.getAggregations().values().stream().findFirst().orElse(null); assertNotNull(aggregations); assertEquals(1, aggregations.getBuckets().size()); assertEquals(ImmutableMap.of("key","0","doc_count",10), aggregations.getBuckets().get(0)); }