Scripted Fields for if/else condition in Kibana 4 Scripted Fields for if/else condition in Kibana 4 elasticsearch elasticsearch

Scripted Fields for if/else condition in Kibana 4


To create a scripted field, you go into the Settings for the index and click on the Scripted Fields tab. Hit Add Scripted Field.

In your case, you will enter f1 as the Name and doc['x'].value == 0 ? 1 : 0 as the Script. You'll then add a second scripted field with f2 as the Name and doc['x'].value != 0 ? 1 : 0 as the script.

The ?: is the ternary operator and works like in most languages -- it evaluates the condition before the ? and if the value is true the expression has the value of whatever is after the ? and if it's false, it has the value of whatever is after the :.