elasticsearch - Scripted Fields for if/else condition in Kibana 4 -
i have numeric fields in elasticsearch, have implement logic need create scripted fields. new kibana 4's scripted fields feature, need regarding basic format used writing basic if else condition in scripted fields. detailed explanation: have number field x in elasticsearch, need create 2 scripted fields f1 , f2 such that,
if x==0
f1 = 1 , f2 = 0
else
f1 = 0 , f2 = 1
just need correct syntax in kibana 4's scripted fields feature. tell if can't done.
more information on scripted fields refer : https://www.elastic.co/guide/en/kibana/current/settings.html
to create scripted field, go settings
index , click on scripted fields
tab. hit add scripted field
.
in case, enter f1
name , doc['x'].value == 0 ? 1 : 0
script. you'll add second scripted field f2
name , doc['x'].value != 0 ? 1 : 0
script.
the ?:
ternary operator , works in languages -- evaluates condition before ?
, if value true
expression has value of whatever after ?
, if it's false, has value of whatever after :
.
Comments
Post a Comment