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

**URL:** <https://discuss.elastic.co/t/can-i-have-document-count-and-sum-in-the-same-bicket/188974>\
**Category:** Elasticsearch\
**Created:** [July 4, 2019, 9:12pm UTC](https://discuss.elastic.co/t/can-i-have-document-count-and-sum-in-the-same-bicket/188974 "2019-07-04T21:12:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arseny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arseny/32/49460_2.png) [@arseny](https://discuss.elastic.co/u/arseny)\
**Post date:** [July 4, 2019, 9:12pm UTC](https://discuss.elastic.co/t/can-i-have-document-count-and-sum-in-the-same-bicket/188974/1 "2019-07-04T21:12:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![arseny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arseny/32/49460_2.png) [@arseny](https://discuss.elastic.co/u/arseny)\
**Post date:** [July 4, 2019, 9:23pm UTC](https://discuss.elastic.co/t/can-i-have-document-count-and-sum-in-the-same-bicket/188974/2 "2019-07-04T21:23:20Z")

</div>

Solved using sub-aggregation correctly

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 1, 2019, 9:23pm UTC](https://discuss.elastic.co/t/can-i-have-document-count-and-sum-in-the-same-bicket/188974/3 "2019-08-01T21:23:23Z")

</div>

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