tcpeiris
(Kavish Peiris)
April 25, 2023, 2:57pm
1
{
"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
}
RabBit_BR
(andre.coelho)
April 25, 2023, 6:58pm
2
Hi @tcpeiris
One option is for you to manipulate the response to the desired output. Have you already implemented something?
tcpeiris
(Kavish Peiris)
April 26, 2023, 7:04am
3
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.
system
(system)
Closed
May 24, 2023, 7:04am
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.