# How can I get the bucket script result unconditionally even when the value is 0?

**URL:** <https://discuss.elastic.co/t/how-can-i-get-the-bucket-script-result-unconditionally-even-when-the-value-is-0/228631>\
**Category:** Elasticsearch\
**Created:** [April 18, 2020, 9:40am UTC](https://discuss.elastic.co/t/how-can-i-get-the-bucket-script-result-unconditionally-even-when-the-value-is-0/228631 "2020-04-18T09:40:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yungyoung\_Ok](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yungyoung_ok/32/43465_2.png) [@Yungyoung\_Ok](https://discuss.elastic.co/u/Yungyoung_Ok)\
**Post date:** [April 18, 2020, 9:40am UTC](https://discuss.elastic.co/t/how-can-i-get-the-bucket-script-result-unconditionally-even-when-the-value-is-0/228631/1 "2020-04-18T09:40:52Z")

</div>

1.Calculate the total time using sum aggs.  
2. Calculate the number of users using cardinality aggs.  
3. Count the total time/number of users using a bucket script to get the average time.

However, if the total time is 0 or the number of users is 0, bucket script results are not provided.  
How can I set it to 0 if there is no current value?

---

<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:** [May 16, 2020, 9:44am UTC](https://discuss.elastic.co/t/how-can-i-get-the-bucket-script-result-unconditionally-even-when-the-value-is-0/228631/2 "2020-05-16T09:44:34Z")

</div>

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