# How to aggregate per keyword in the match list

**URL:** <https://discuss.elastic.co/t/how-to-aggregate-per-keyword-in-the-match-list/217946>\
**Category:** Elasticsearch\
**Created:** [February 5, 2020, 9:48am UTC](https://discuss.elastic.co/t/how-to-aggregate-per-keyword-in-the-match-list/217946 "2020-02-05T09:48:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mich\_Talebzadeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mich_talebzadeh/32/62107_2.png) [@Mich\_Talebzadeh](https://discuss.elastic.co/u/Mich_Talebzadeh)\
**Post date:** [February 5, 2020, 9:48am UTC](https://discuss.elastic.co/t/how-to-aggregate-per-keyword-in-the-match-list/217946/1 "2020-02-05T09:48:58Z")

</div>

Hi,

I have a basic code that provides the sum spent for all items in the following list

"query": {  
"bool": {  
"should": [  
{ "match": { "description": "A" }}  
, { "match": { "description": "B" }}  
, { "match": { "description": "C" }}  
, { "match": { "description": "D" }}  
],  
"minimum\_should\_match": 1,  
"must": [  
{ "range": { "transactiondate": { "gte": "2018-01-01" } } }  
, { "range": { "moneyout": { "gt": 100 } } }  
],  
"must\_not": {  
"bool": {  
"must": [  
{ "match": { "transactiontype": "ATM Cash Withdrawal" } }  
]  
}  
}  
}  
},  
"aggs" : {  
"total\_spent" : {  
"sum" : {  
"field" : "moneyout",  
"script" : {  
"source": "\_value"  
}  
}  
}  
}  
}

Now this works fine and get to total sum for "moneyout" field for all matches..

However, I would like to get the sum for each match i.e. A and B and C and D in the above list plus the total sum. How can I achieve that?

Thanks,

Mich

---

<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:** [March 4, 2020, 9:49am UTC](https://discuss.elastic.co/t/how-to-aggregate-per-keyword-in-the-match-list/217946/2 "2020-03-04T09:49:14Z")

</div>

Closed on March 4, 2020, 9:49am UTC

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