How to combine terms and sum aggregations

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?

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