Map Composite Aggregation Payload in Java using Java Client 8.7

{
  "buckets": [
    {
      "key": {
        "SUBJNAME": "ALL",
        "ASOFYEARS": 2018
      },
      "doc_count": 240,
      "cnt_subj": {
        "value": 25521935824
      },
      "cnt_dwnl": {
        "value": 4224
      }
    }
  ]
}

I need the output to look like this in Java.

{
  "SUBJNAME": "ALL",
  "ASOFYEARS": 2018,
  "cnt_subj": 25521935824,
  "cnt_dwnl": 4224
}

Hi @tcpeiris

One option is for you to manipulate the response to the desired output. Have you already implemented something?

for (CompositeBucket bucket : buckets) {

                    Map<String, Object> subBucket = new LinkedHashMap<>();

                    for (Map.Entry<String, FieldValue> entry : bucket.key().entrySet()) {
                        subBucket.put(entry.getKey(), entry.getValue()._get());
                    }
                    query.getAggregate().getFunctions().forEach(func -> {

                        if (func.getType().equals("sum")) {
                            subBucket.put(func.getName(), bucket.aggregations().get(func.getName()).sum().value());
                        } else if (func.getType().equals("avg")) {
                            subBucket.put(func.getName(), bucket.aggregations().get(func.getName()).avg().value());
                        }

                    });

                }

Hi @RabBit_BR, I was able to achieve this by following implementation. Let me know if you have any suggestions.