# Return value occurence percentage in multi-term field

**URL:** <https://discuss.elastic.co/t/return-value-occurence-percentage-in-multi-term-field/172216>\
**Category:** Elasticsearch\
**Created:** [March 13, 2019, 8:47pm UTC](https://discuss.elastic.co/t/return-value-occurence-percentage-in-multi-term-field/172216 "2019-03-13T20:47:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bram](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@bram](https://discuss.elastic.co/u/bram)\
**Post date:** [March 13, 2019, 8:47pm UTC](https://discuss.elastic.co/t/return-value-occurence-percentage-in-multi-term-field/172216/1 "2019-03-13T20:47:28Z")

</div>

Hey,

With the documents:  
documentA: { "code": ["foo", "bar"] }  
documentB: { "code": ["foo", "foo"] }  
documentC: { "code": ["bar", "quux"] }  
documentD: { "code": ["quux", "bar"] }

I would like to get the following statistics:  
count\_total: 8  
count\_foo: 3  
count\_bar: 3  
percentage\_foo: 37,5%  
percentage\_bar: 37,5%

The use case is that we want to get an alert if a percentage of a specific value is above a certain number. And possibly a dashboard with the percentage over time, using the @timestamp field.

---

<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:** [April 10, 2019, 8:47pm UTC](https://discuss.elastic.co/t/return-value-occurence-percentage-in-multi-term-field/172216/2 "2019-04-10T20:47:33Z")

</div>

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