# Perform significant terms aggregation in Elastic search based on sum of a field rather than count if documents

**URL:** <https://discuss.elastic.co/t/perform-significant-terms-aggregation-in-elastic-search-based-on-sum-of-a-field-rather-than-count-if-documents/207247>\
**Category:** Elasticsearch\
**Created:** [November 10, 2019, 4:15pm UTC](https://discuss.elastic.co/t/perform-significant-terms-aggregation-in-elastic-search-based-on-sum-of-a-field-rather-than-count-if-documents/207247 "2019-11-10T16:15:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaibhav\_gupta1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vaibhav_gupta1/32/57439_2.png) [@vaibhav\_gupta1](https://discuss.elastic.co/u/vaibhav_gupta1)\
**Post date:** [November 10, 2019, 4:15pm UTC](https://discuss.elastic.co/t/perform-significant-terms-aggregation-in-elastic-search-based-on-sum-of-a-field-rather-than-count-if-documents/207247/1 "2019-11-10T16:15:15Z")

</div>

Suppose I have these three documents. I wish to apply significant terms on the token field. By default, significance would be calculated based on the count of foreground and background sets. E.g. For the term Annine, the count of docs in foreground is 1 out of 1 whereas in the background is also 1 out of 3.

\<{  
"token":"left",  
"count":5  
},  
{  
"token":"left",  
"count":15  
},  
{  
"token":"Annine",  
"count":25  
} \>

However, I wish to calculate the significance based on the sum of the count. i.e. for Annine, foreground is 25 out of 25 whereas in background it is 25 out of 45. How can i implement this?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [November 12, 2019, 11:44am UTC](https://discuss.elastic.co/t/perform-significant-terms-aggregation-in-elastic-search-based-on-sum-of-a-field-rather-than-count-if-documents/207247/2 "2019-11-12T11:44:56Z")

</div>

Hi Vaibhav,  
We have an old [open issue](https://github.com/elastic/elasticsearch/issues/12309) for this which includes some comments on a possible workaround using scripted metric aggregations.

---

<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:** [December 10, 2019, 11:45am UTC](https://discuss.elastic.co/t/perform-significant-terms-aggregation-in-elastic-search-based-on-sum-of-a-field-rather-than-count-if-documents/207247/3 "2019-12-10T11:45:23Z")

</div>

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