Can I have document count and sum in the same bicket?

I have documents of shape

{ amount, status, timestamp ...other } 

and I was wondering if I can group them by day, status and have count and sum(amount)?

Basically, the response be:

"buckets" : [
  {
    "key" : "COMPLETED",
    "doc_count" : 19395,
    "amount" : 452455
  },
  {
    "key" : "CANCELLED",
    "doc_count" : 126,
    "amount" : 95322
  },
  ...
]

Currently, I'm stuck trying to add "amount" there.

Solved using sub-aggregation correctly

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.