# Painless help

**URL:** <https://discuss.elastic.co/t/painless-help/85297>\
**Category:** Elasticsearch\
**Created:** [May 10, 2017, 7:24pm UTC](https://discuss.elastic.co/t/painless-help/85297 "2017-05-10T19:24:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zfs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zfs/32/13370_2.png) [@Zfs](https://discuss.elastic.co/u/Zfs)\
**Post date:** [May 10, 2017, 7:24pm UTC](https://discuss.elastic.co/t/painless-help/85297/1 "2017-05-10T19:24:08Z")

</div>

Hello,

Trying to use the example I'm trying to count the values for 'count\_value' field then multiple the result by busy. For some odd reason I can use +, - but \* just returns the busy value.

I'm trying to run the below.

```
double busy = _value; double total = 0; for (int i = 0; i < doc['count_value'].length; ++i) { total += doc['count_value'][i]; } return busy * total;

```

Is there a better way to run something like this?

Thanks

---

<div class="post-metadata">

**Author:** ![Zfs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zfs/32/13370_2.png) [@Zfs](https://discuss.elastic.co/u/Zfs)\
**Post date:** [May 11, 2017, 2:05pm UTC](https://discuss.elastic.co/t/painless-help/85297/3 "2017-05-11T14:05:07Z")

</div>

I've made little progress.

count\_value is a value of 1 for every hour. I use this to "sum" the hours in a day or multiple days selected from the time range. example a range of "yesterday" = 24.

```
 ((_value * 0.10) / (doc['count_value'].value * 10))*100

```

This works well, the result is 24 for "yesterday" for each hour in the day. But the above doc['count\_value'].value is not the total for the range but rather the value for the hour = 1.

Is it possible with an inline script to get the total of doc['count\_value'].value of the entire range to be used in each bucket calculation? Or a way to pass the "bucket count" back to the script?

Thanks

---

<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:** [June 8, 2017, 2:07pm UTC](https://discuss.elastic.co/t/painless-help/85297/4 "2017-06-08T14:07:51Z")

</div>

Closed on June 8, 2017, 2:07pm UTC

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