# Multi-line scripts in kibana's json input

**URL:** <https://discuss.elastic.co/t/multi-line-scripts-in-kibanas-json-input/232198>\
**Category:** Kibana\
**Created:** [May 12, 2020, 10:27am UTC](https://discuss.elastic.co/t/multi-line-scripts-in-kibanas-json-input/232198 "2020-05-12T10:27:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geo909](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geo909/32/65605_2.png) [@geo909](https://discuss.elastic.co/u/geo909)\
**Post date:** [May 12, 2020, 10:27am UTC](https://discuss.elastic.co/t/multi-line-scripts-in-kibanas-json-input/232198/1 "2020-05-12T10:27:13Z")

</div>

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**

 ![examples](https://us1.discourse-cdn.com/elastic/original/3X/2/1/210f3c8ed1be4bcd3ff824121577931e42366764.png)

---

<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:** [June 9, 2020, 10:27am UTC](https://discuss.elastic.co/t/multi-line-scripts-in-kibanas-json-input/232198/2 "2020-06-09T10:27:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
