# Example script does not work

**URL:** <https://discuss.elastic.co/t/example-script-does-not-work/174265>\
**Category:** Kibana\
**Created:** [March 28, 2019, 8:14am UTC](https://discuss.elastic.co/t/example-script-does-not-work/174265 "2019-03-28T08:14:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zoltan\_Koszegi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoltan_koszegi/32/42955_2.png) [@Zoltan\_Koszegi](https://discuss.elastic.co/u/Zoltan_Koszegi)\
**Post date:** [March 28, 2019, 8:14am UTC](https://discuss.elastic.co/t/example-script-does-not-work/174265/1 "2019-03-28T08:14:38Z")

</div>

Hi! I'm trying to create an email message based on the number of hits. For instance, I would iterate through the ctx.payload.hits.hits list and display simple text in the email body listing a couple of properties from the found events. For achieving this I studied the scripting capabilities e.g. [this page](https://www.elastic.co/guide/en/elasticsearch/painless/6.7/painless-watcher-transform-context.html) but found that the script enclosed by the three double quotes are not JSON syntax. Hence this is cannot be put into the Kibana's watcher editor or any other JSON editor. What was your intention with this syntax? It caused me a lot of headaches.

---

<div class="post-metadata">

**Author:** ![christophilus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christophilus/32/42991_2.png) [@christophilus](https://discuss.elastic.co/u/christophilus)\
**Post date:** [March 28, 2019, 1:38pm UTC](https://discuss.elastic.co/t/example-script-does-not-work/174265/2 "2019-03-28T13:38:18Z")

</div>

This is probably a question best asked here: [https://discuss.elastic.co/c/elasticsearch](https://discuss.elastic.co/c/elasticsearch)

As it's not Kibana-related. I'm not sure why the example would have been written that way. It looks like maybe a bug in the way our docs get generated. Here's the correct string representation:

```
"return [\n 'money_makers': ctx.payload.aggregations.theatres.buckets.stream() \n .filter(t -> { \n return t.money.value > 50000\n })\n .map(t -> { \n return ['play': t.key, 'total_value': t.money.value]\n }).collect(Collectors.toList()), \n 'duds' : ctx.payload.aggregations.theatres.buckets.stream() \n .filter(t -> {\n return t.money.value < 15000\n })\n .map(t -> {\n return ['play': t.key, 'total_value': t.money.value]\n }).collect(Collectors.toList())\n ]"
```

---

<div class="post-metadata">

**Author:** ![Zoltan\_Koszegi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoltan_koszegi/32/42955_2.png) [@Zoltan\_Koszegi](https://discuss.elastic.co/u/Zoltan_Koszegi)\
**Post date:** [March 28, 2019, 9:03pm UTC](https://discuss.elastic.co/t/example-script-does-not-work/174265/3 "2019-03-28T21:03:20Z")

</div>

Actually, it does not work. It seems the only way to separate a string into multiple lines if every line enclosed by quotes and every line terminated by a comma. This is the JSON array syntax. [See this here.](https://www.gun.io/blog/multi-line-strings-in-json). Whenever you put a new line into a "script" property you get an "invalid JSON" error in the Kibana's watch editor. It's really painful to write any significant script in one line. Did I miss something?

---

<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:** [April 25, 2019, 9:07pm UTC](https://discuss.elastic.co/t/example-script-does-not-work/174265/4 "2019-04-25T21:07:32Z")

</div>

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