@Test void one_bucket_one_metric_should_pass() { String response = "{\n" + " \"composite#composite_buckets\": {\n" + " \"after_key\": {\n" + " \"type\": \"sale\"\n" + " },\n" + " \"buckets\": [\n" + " {\n" + " \"key\": {\n" + " \"type\": \"cost\"\n" + " },\n" + " \"doc_count\": 2,\n" + " \"avg#avg\": {\n" + " \"value\": 20\n" + " }\n" + " },\n" + " {\n" + " \"key\": {\n" + " \"type\": \"sale\"\n" + " },\n" + " \"doc_count\": 2,\n" + " \"avg#avg\": {\n" + " \"value\": 105\n" + " }\n" + " }\n" + " ]\n" + " }\n" + "}"; assertThat(parse(response), containsInAnyOrder(ImmutableMap.of("type", "cost", "avg", 20d), ImmutableMap.of("type", "sale", "avg", 105d))); }
public static List<Map<String, Object>> parse(Aggregations aggregations) { List<Aggregation> aggregationList = aggregations.asList(); ImmutableList.Builder<Map<String, Object>> builder = new ImmutableList.Builder<>(); for (Aggregation aggregation : aggregationList) { if (aggregation instanceof CompositeAggregation) { for (CompositeAggregation.Bucket bucket : ((CompositeAggregation) aggregation).getBuckets()) { builder.add(parse(bucket)); } } else { builder.add(parseInternal(aggregation)); } } return builder.build(); }
ElasticsearchAggregationResponseParser { public static List<Map<String, Object>> parse(Aggregations aggregations) { List<Aggregation> aggregationList = aggregations.asList(); ImmutableList.Builder<Map<String, Object>> builder = new ImmutableList.Builder<>(); for (Aggregation aggregation : aggregationList) { if (aggregation instanceof CompositeAggregation) { for (CompositeAggregation.Bucket bucket : ((CompositeAggregation) aggregation).getBuckets()) { builder.add(parse(bucket)); } } else { builder.add(parseInternal(aggregation)); } } return builder.build(); } }
ElasticsearchAggregationResponseParser { public static List<Map<String, Object>> parse(Aggregations aggregations) { List<Aggregation> aggregationList = aggregations.asList(); ImmutableList.Builder<Map<String, Object>> builder = new ImmutableList.Builder<>(); for (Aggregation aggregation : aggregationList) { if (aggregation instanceof CompositeAggregation) { for (CompositeAggregation.Bucket bucket : ((CompositeAggregation) aggregation).getBuckets()) { builder.add(parse(bucket)); } } else { builder.add(parseInternal(aggregation)); } } return builder.build(); }  }
ElasticsearchAggregationResponseParser { public static List<Map<String, Object>> parse(Aggregations aggregations) { List<Aggregation> aggregationList = aggregations.asList(); ImmutableList.Builder<Map<String, Object>> builder = new ImmutableList.Builder<>(); for (Aggregation aggregation : aggregationList) { if (aggregation instanceof CompositeAggregation) { for (CompositeAggregation.Bucket bucket : ((CompositeAggregation) aggregation).getBuckets()) { builder.add(parse(bucket)); } } else { builder.add(parseInternal(aggregation)); } } return builder.build(); }  static List<Map<String, Object>> parse(Aggregations aggregations); }
ElasticsearchAggregationResponseParser { public static List<Map<String, Object>> parse(Aggregations aggregations) { List<Aggregation> aggregationList = aggregations.asList(); ImmutableList.Builder<Map<String, Object>> builder = new ImmutableList.Builder<>(); for (Aggregation aggregation : aggregationList) { if (aggregation instanceof CompositeAggregation) { for (CompositeAggregation.Bucket bucket : ((CompositeAggregation) aggregation).getBuckets()) { builder.add(parse(bucket)); } } else { builder.add(parseInternal(aggregation)); } } return builder.build(); }  static List<Map<String, Object>> parse(Aggregations aggregations);  }