# How to create a conditional scripted field in Kibana

**URL:** <https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087>\
**Category:** Kibana\
**Created:** [October 27, 2015, 3:32pm UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087 "2015-10-27T15:32:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [October 27, 2015, 3:32pm UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087/1 "2015-10-27T15:32:30Z")

</div>

Hi Experts,

I want to create a scripted field in kibana . My requirement is to use words rather numbers . So I have a field Priority =1 to 10 here 1 is lowest and 10 is the highest . So it is like if priority in [1,5] then it is low or if priority in [6,10] then it should be high .

Please help

---

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [October 27, 2015, 4:12pm UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087/2 "2015-10-27T16:12:12Z")

</div>

I tried this but it does not work  
doc['priority'].value == 9 ? high : low

Rather doc['priority'].value == 9 ? 1 : 0 is working fine but it does not solve my problem as I do not want numeric output , Plus how I can mentions multiple conditions here ?

---

<div class="post-metadata">

**Author:** ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)\
**Post date:** [October 29, 2015, 6:20am UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087/3 "2015-10-29T06:20:25Z")

</div>

Lucene expressions (default scripting language) only work on numerical data, so you can't introduce strings. If you want to go this route, you have to use Groovy.

---

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [October 29, 2015, 6:27am UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087/4 "2015-10-29T06:27:36Z")

</div>

Thank you Tanya,

Lets assume I have a Groovy Script , my concern is where I need to call that I was searching for Groovy script in Elasticsearch , I saw some examples but those are again on numerical data . Can you suggest some simple example for string data.

Thanks  
VG

---

<div class="post-metadata">

**Author:** ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)\
**Post date:** [October 29, 2015, 6:30am UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087/5 "2015-10-29T06:30:00Z")

</div>

There is some info on how to do indicate you are using Groovy here with static scripts: [Calling groovy script from Kibana](https://discuss.elastic.co/t/calling-groovy-script-from-kibana/2542/3)

Alternatively, you can enable dynamic groovy (though I wouldn't recommend it, as it's insecure).

---

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [October 29, 2015, 7:34am UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087/6 "2015-10-29T07:34:34Z")

</div>

Thanks It helps, need another favor . I am trying below code but it is not working . I wan to create a field Priority\_word only if the condition is true . So if the priority.value is between 1 to 3 then new scripted field should say low else medium.

"script\_fields" : { "priority\_word" : { "script" : "if (doc['priority'].value \>= 1) and (doc['priority'].value \>= 3) { doc['priority\_word'] = 'low'" } } }

---

<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:** [July 6, 2017, 2:10pm UTC](https://discuss.elastic.co/t/how-to-create-a-conditional-scripted-field-in-kibana/33087/7 "2017-07-06T14:10:26Z")

</div>


