Dear all,
I'm trying to understand how to use scripted fields in Kibana's JSON input, and I am having a hard time with multi-line scripts.
For example, I have a line visualization and I want to define a metric on the Y-Axis, with a new variable which is the difference of two existing variables. Using an inline expression, I can put the following in the json input and it works as expected, giving me a visualization of the difference of these fields:
{
"script" : {
"source" : "doc['reservationAmount'].value - doc['cancellation.finalRefundAmount'].value",
"lang" : "painless"
}
}
However, I sometimes want to use more complicated, multi-line scripts, so I would prefer to use the syntax with triple quotation marks. I would expect that the following would be equivalent to the above, but it doesn't work, giving me an error :
{
"script" : {
"lang" : "painless",
"source" : """
return doc['reservationAmount'].value - doc['cancellation.finalRefundAmount'].value
"""
}
}
Could somebody explain why the second syntax doesn't work? Can I adapt it in order to work?
Please bare in mind that 1) this is just a demonstration example, in general I would like to know how to use the multi-line syntax in order to create more complicated scripts and 2) I know how to define scripted fields in kibana, but I don't want to do that for scripted fields that may be used just once in a visualization.
Thank you in advance
Screenshots