# Filter data based on script result

**URL:** <https://discuss.elastic.co/t/filter-data-based-on-script-result/216277>\
**Category:** Kibana\
**Created:** [January 23, 2020, 3:06pm UTC](https://discuss.elastic.co/t/filter-data-based-on-script-result/216277 "2020-01-23T15:06:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dknecht](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@dknecht](https://discuss.elastic.co/u/dknecht)\
**Post date:** [January 23, 2020, 3:06pm UTC](https://discuss.elastic.co/t/filter-data-based-on-script-result/216277/1 "2020-01-23T15:06:15Z")

</div>

Hi

The script shown in the "JSON Input" field below computes bandwidth utilization in percent of the interface's nominal bandwidth:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/1/912346f84a934fa7561b6c2c83cc11430ab1fd55.png)

I'd like to display only those interfaces where the computed result of that script is \>80. How can this be done?

Thanks for your help

David

PS: I am aware that my question is related to the unanswered question [Show only the average values that are more than 80%](https://discuss.elastic.co/t/show-only-the-average-values-that-are-more-than-80/214425).

---

<div class="post-metadata">

**Author:** ![Elvis\_Saravia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elvis_saravia/32/45624_2.png) [@Elvis\_Saravia](https://discuss.elastic.co/u/Elvis_Saravia)\
**Post date:** [January 24, 2020, 8:57am UTC](https://discuss.elastic.co/t/filter-data-based-on-script-result/216277/2 "2020-01-24T08:57:07Z")

</div>

Hi @dknecht,  
Thanks for taking the time to post here in the forum.  
If I understood your problem well and what you want to achieve, you may want to create this script as a separate scripted field. You can perform the same metric aggregation so you get the chart and then you can run a quick search on it from the search bar such as `newly_scripted_field > 80`.

Here is some info on scripted fields: [https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

Let me know if that would work.

---

<div class="post-metadata">

**Author:** ![dknecht](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@dknecht](https://discuss.elastic.co/u/dknecht)\
**Post date:** [January 30, 2020, 1:10pm UTC](https://discuss.elastic.co/t/filter-data-based-on-script-result/216277/3 "2020-01-30T13:10:39Z")

</div>

Hi Elvis

Thanks for your suggestion. Unfortunately, I don't get it running.

Based on the Kibana documentation (see below) I get the impression that it might not work at all:

"Scripted field values are computed at query time so they aren’t indexed and cannot be searched using Kibana’s default query language." (see: [https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html))

Is there anything I am misunderstanding?

This is how far I got trying to implement your suggestion (using Kibana 4.5.1):

/etc/elasticsearch/elasticsearch.yml:  
...  
script.inline: true  
script.indexed: true

Define the scripted field:

 ![kibana1](https://us1.discourse-cdn.com/elastic/original/3X/d/0/d0c1566703524158e28d6236fef90f386fe5b75b.png)

Test the scripted field:

 ![kibana_2](https://us1.discourse-cdn.com/elastic/original/3X/7/0/706bb563836ba828ef5a78c79e17ea0544eed433.png)

Thanks and kind regards

David

---

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [January 30, 2020, 7:13pm UTC](https://discuss.elastic.co/t/filter-data-based-on-script-result/216277/4 "2020-01-30T19:13:07Z")

</div>

Wow, that's a pretty old version of Kibana. I think it's 4.x? I'm not sure if this has changed since then, but on current versions of the stack I can query or filter on a number type scripted field.

---

<div class="post-metadata">

**Author:** ![Elvis\_Saravia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elvis_saravia/32/45624_2.png) [@Elvis\_Saravia](https://discuss.elastic.co/u/Elvis_Saravia)\
**Post date:** [January 30, 2020, 7:35pm UTC](https://discuss.elastic.co/t/filter-data-based-on-script-result/216277/5 "2020-01-30T19:35:10Z")

</div>

As @LeeDr points out, I am using 7.5.0 with KQL and it works fine querying the scripted field as I did. Your old version of Kibana doesn't have this capability I believe.

---

<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:** [February 27, 2020, 7:35pm UTC](https://discuss.elastic.co/t/filter-data-based-on-script-result/216277/6 "2020-02-27T19:35:13Z")

</div>

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