# Help in scripted fields - Kibana

**URL:** <https://discuss.elastic.co/t/help-in-scripted-fields-kibana/54245>\
**Category:** Kibana\
**Created:** [June 29, 2016, 7:13am UTC](https://discuss.elastic.co/t/help-in-scripted-fields-kibana/54245 "2016-06-29T07:13:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvignesh92](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvignesh92](https://discuss.elastic.co/u/pvignesh92)\
**Post date:** [June 29, 2016, 7:13am UTC](https://discuss.elastic.co/t/help-in-scripted-fields-kibana/54245/1 "2016-06-29T07:13:54Z")

</div>

I have added a scripted field with the below condition but doesn't seem to create any value of 2 or 1 and giving 0 instead. Not sure what I'm missing.

"\_source.fs.used\_p" \> 0.01 ? 2 : 1

The data is from topbeat and in of the form  
"fs":{"device\_name":"none","total":0,"used":0,"used\_p":0,"free":0,"avail":0,"files":0,"free\_files":0}

Any help.

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [June 29, 2016, 6:28pm UTC](https://discuss.elastic.co/t/help-in-scripted-fields-kibana/54245/2 "2016-06-29T18:28:20Z")

</div>

The formatting of your scripted field is wrong, see [the Lucene Expression docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_lucene_expressions_scripts).

I'm not sure that it works with nested objects, but I suspect it does. Try this in your scripted field definition:

`doc['fs.usedp'].value > 0.01 ? 2 : 1`

---

<div class="post-metadata">

**Author:** ![pvignesh92](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvignesh92](https://discuss.elastic.co/u/pvignesh92)\
**Post date:** [June 30, 2016, 10:49am UTC](https://discuss.elastic.co/t/help-in-scripted-fields-kibana/54245/3 "2016-06-30T10:49:52Z")

</div>

Thanks Joe for the response. I could get this done. This is the final script that worked for me.

(doc['cpu.user\_p'].value \> 0.5 || doc['mem.used\_p'].value \> 0.2 || doc['fs.used\_p'].value \> 0.3) ? 2 : (doc['cpu.user\_p'].value \> 0.5 || doc['mem.used\_p'].value \> 0.2 || doc['fs.used\_p'].value \> 0.3) ? 1 : 0

---

<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, 1:48pm UTC](https://discuss.elastic.co/t/help-in-scripted-fields-kibana/54245/4 "2017-07-06T13:48:37Z")

</div>


