# How to combine terms and sum aggregations

**URL:** <https://discuss.elastic.co/t/how-to-combine-terms-and-sum-aggregations/217109>\
**Category:** Elasticsearch\
**Created:** [January 30, 2020, 6:07am UTC](https://discuss.elastic.co/t/how-to-combine-terms-and-sum-aggregations/217109 "2020-01-30T06:07:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fenster25](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fenster25/32/55546_2.png) [@fenster25](https://discuss.elastic.co/u/fenster25)\
**Post date:** [January 30, 2020, 6:07am UTC](https://discuss.elastic.co/t/how-to-combine-terms-and-sum-aggregations/217109/1 "2020-01-30T06:07:03Z")

</div>

So I want to run a sum aggregation after I have ran a terms aggregation on my index. This is what a document in my index looks like

```
{
    "_index" : "pr-delta",
    "_type" : "_doc",
    "_id" : "ot5Y8W8BHWq44CdbYJ3n",
    "_score" : 1.0,
    "_source" : {
      "author" : "AravinthG",
      "title" : "gem updates",
      "created_at" : "2020-01-28T10:45:57Z",
      "pr_number" : 367943382,
      "merged" : false,
      "merged_by" : "",
      "body" : ""
    }

```

I want to first of all segregrate all documents into different buckets for each "author". Once all the docs belonging to the same author are in their respective buckets I want to run a Sum aggregation on all my buckets for find the sum of the delta field in the docs of each bucket and plot a graph of the sum of deltas for each author over time

So that eventually I can visualize this using a line graph in kibana which shows the sum of delta for each author over time

This was the aggregation body I was using but I am sure this is wrong

```
{
"aggs" : {
    "authors" : {
        "terms" : { "field" : "author.keyword",
        			"size": 150
        }
    },
    "aggs": {
    	"delta_sum": {
    		"sum": {"field": "delta"}
    	}
    }
   }
}

```

Am I modelling my docs correctly for this? is my aggreagation correct?

---

<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:** [February 27, 2020, 6:07am UTC](https://discuss.elastic.co/t/how-to-combine-terms-and-sum-aggregations/217109/2 "2020-02-27T06:07:04Z")

</div>

Closed on February 27, 2020, 6:07am UTC

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