# Can we use scripted field in kibana in term aggregation?

**URL:** <https://discuss.elastic.co/t/can-we-use-scripted-field-in-kibana-in-term-aggregation/251523>\
**Category:** Kibana\
**Created:** [October 9, 2020, 4:04am UTC](https://discuss.elastic.co/t/can-we-use-scripted-field-in-kibana-in-term-aggregation/251523 "2020-10-09T04:04:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![le\_ba\_nam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/le_ba_nam/32/75148_2.png) [@le\_ba\_nam](https://discuss.elastic.co/u/le_ba_nam)\
**Post date:** [October 9, 2020, 4:04am UTC](https://discuss.elastic.co/t/can-we-use-scripted-field-in-kibana-in-term-aggregation/251523/1 "2020-10-09T04:04:45Z")

</div>

I created scripted field in kibana named service\_exception.keyword. Now I am trying to create a watcher, which aims to catch the most occurrences exception service. But it not work. I tried replace it by another field and it work.

Is scripted field problem? If it is, Is it have any solution to deal with that? Thanks.

---

<div class="post-metadata">

**Author:** ![gmmorris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gmmorris/32/72624_2.png) [@gmmorris](https://discuss.elastic.co/u/gmmorris)\
**Post date:** [October 9, 2020, 9:27am UTC](https://discuss.elastic.co/t/can-we-use-scripted-field-in-kibana-in-term-aggregation/251523/2 "2020-10-09T09:27:23Z")

</div>

Hi,

You're right, the Scripted Fields are the problem.  
It's best to think of Scripted Fields as a way of computing on the data when it is loaded by Kibana, and so it is only available in Kibana itself.  
Watcher, on the other hand, runs inside of Elasticsearch and so it can only trigger based on the data that's available there.

The solution for your use case is, I believe, using some kind of an Inline Script which are evaluated inside of Elasticsearch and so are accessible to Watcher.

You can read all about scripting here:

> **[Scripting | Elasticsearch Reference \[7.9\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html)**

And further here:

> **[How to use scripts | Elasticsearch Reference \[7.9\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html)**

---

<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 6, 2020, 9:27am UTC](https://discuss.elastic.co/t/can-we-use-scripted-field-in-kibana-in-term-aggregation/251523/3 "2020-11-06T09:27:25Z")

</div>

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