How to create a conditional scripted field in Kibana

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

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 ?

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.

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

There is some info on how to do indicate you are using Groovy here with static scripts: Calling groovy script from Kibana

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

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'" } } }