# Can I use the result of a query in other scripted query to perform calculations?

**URL:** <https://discuss.elastic.co/t/can-i-use-the-result-of-a-query-in-other-scripted-query-to-perform-calculations/152301>\
**Category:** Kibana\
**Created:** [October 12, 2018, 9:00pm UTC](https://discuss.elastic.co/t/can-i-use-the-result-of-a-query-in-other-scripted-query-to-perform-calculations/152301 "2018-10-12T21:00:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulo.leao](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@paulo.leao](https://discuss.elastic.co/u/paulo.leao)\
**Post date:** [October 12, 2018, 9:00pm UTC](https://discuss.elastic.co/t/can-i-use-the-result-of-a-query-in-other-scripted-query-to-perform-calculations/152301/1 "2018-10-12T21:00:26Z")

</div>

I am trying to create a query to output a ratio. The first number is the sum aggregation of the OutageTime field. The second number is a scripted field.

Here is my mapping:

> <https://gist.github.com/591573/5f7b8b891ed6e6cd246ba76878569a63#file-gistfile1-txt>

Here is my query:

> <https://gist.github.com/591573/fb3bf3b50a1425c1a1f9440d4ee60462#file-gistfile1-txt>

So my question is: is it possible to use the result of the aggregation in the scripted query?

---

<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:** [November 9, 2018, 9:00pm UTC](https://discuss.elastic.co/t/can-i-use-the-result-of-a-query-in-other-scripted-query-to-perform-calculations/152301/2 "2018-11-09T21:00:27Z")

</div>

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