Aggregation with java High Level Rest Client

Thank you very much,

I just realized after reading your code that I'm actually printing hits, not aggregations. There wasn't any problem with my code :slight_smile:

I'm glad I found it before someone else so I can be less embarrassed.

To print the aggregations above you can use this Its raw but usable:

        Histogram agg = searchResponse.getAggregations().get("date_aggregation");

    // For each entry
    for (Histogram.Bucket entry : agg.getBuckets()) {
        Min min_agg = entry.getAggregations().get("minValue");
        Max max_agg = entry.getAggregations().get("maxValue");
        Avg avg_agg = entry.getAggregations().get("avgValue");
        Sum sum_agg = entry.getAggregations().get("totalValue");
        System.out.println("minValue: " +min_agg.getValue()+" maxValue: " +max_agg.getValue()+" avgValue: " +avg_agg.getValue()+" totalValue: " +sum_agg.getValue());
    }
1 Like