# Calling groovy script from Kibana

**URL:** https://discuss.elastic.co/t/calling-groovy-script-from-kibana/2542
**Category:** Kibana
**Created:** [June 12, 2015, 6:43am UTC](https://discuss.elastic.co/t/calling-groovy-script-from-kibana/2542 "2015-06-12T06:43:23Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![pickypg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pickypg/32/62409_2.png) [@pickypg](https://discuss.elastic.co/u/pickypg)
#### Post date: [June 17, 2015, 5:04am UTC](https://discuss.elastic.co/t/calling-groovy-script-from-kibana/2542/3 "2015-06-17T05:04:01Z")

</div>

Hi Darpan,

You _can_ use Groovy scripts within Kibana, but you have to use some of its advanced features to effectively make it do what you want. However, the way to do it depends on where the script needs to go. Can you write the query that you _want_ to be processed?

```
{
  "query" : {
    "filtered" : {
      "script" : {
        "script" : "your-script-name"
      }
    }
  }
}

```

If that's the case, then you can actually supply the inner-`query` portion in the Kibana search box:

![](https://us1.discourse-cdn.com/elastic/original/2X/7/7394716d0752381c32adb905bbbcca15e875707b.png)

```
{ "filtered" : { "filter" : { "script" : { "script" : "your-script-name" } } } }

```

* * *

If you want to use your script to customize an aggregation value, then you can do that too, but it takes a few extra steps.

1. Create a custom script field. The value of it is irrelevant, but this is limited because Kibana's script fields are currently only able to use Lucene Expressions, which can only work with numeric fields (not dates, nor strings). For this example, I created one named `custom.count`.

2. In the Visualization, select the script field.

3. Once selected, expand the "Advanced" link below the field.

4. Under the advanced link, enter your script into the JSON Input field as shown. Be sure to add the `"lang" : "groovy"` portion in order to override the script field's `"lang" : "expression"`.

5. From there, the `custom.count` field (as shown) is replaced with the JSON Input that you supply. Any field(s) that you supply, such as `"script"` or `"lang"` will override those supplied by Kibana. If you don't override it, then it gets combined with your input. This is why it's necessary to create a script field.

Hope that helps.

---

_[View the full topic](https://discuss.elastic.co/t/calling-groovy-script-from-kibana/2542)._
