# Stream List Output Formatting in Script (for use in Watcher actions)

**URL:** <https://discuss.elastic.co/t/stream-list-output-formatting-in-script-for-use-in-watcher-actions/100587>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [September 14, 2017, 6:10pm UTC](https://discuss.elastic.co/t/stream-list-output-formatting-in-script-for-use-in-watcher-actions/100587 "2017-09-14T18:10:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![damunk](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@damunk](https://discuss.elastic.co/u/damunk)\
**Post date:** [September 14, 2017, 6:10pm UTC](https://discuss.elastic.co/t/stream-list-output-formatting-in-script-for-use-in-watcher-actions/100587/1 "2017-09-14T18:10:25Z")

</div>

I've been trying to develop a script that can be used for a number different watcher tasks. I came across this this post and it was quite helpful in showing me how to map the output of two aggregations. However, I don't understand painless or Java well enough to get the output of this scipt to print prettier. Can someone point me in the right direction?

[Source Thread](https://discuss.elastic.co/t/how-to-show-memory-usage-is-at-values-percent/92585)

```
{
  "script": {
"source": "return ['hosts' : ctx.payload.aggregations.hosts.buckets.stream().map(b -> [b.key: b.values.value]).collect(Collectors.toList()) ]",
"lang": "painless"
  }
}

```

Existing output (sample):

> {0={dev01.foo.bar=0.892}, 1={dev02.foo.bar=0.8310000000000001})

Preferred output (something with line breaks and less array postion designations):

> dev01.foo.bar=0.892  
> dev02.foo.bar=0.8310000000000001

Much appreciation in advance, all.

-Z

---

<div class="post-metadata">

**Author:** ![damunk](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@damunk](https://discuss.elastic.co/u/damunk)\
**Post date:** [September 15, 2017, 2:10pm UTC](https://discuss.elastic.co/t/stream-list-output-formatting-in-script-for-use-in-watcher-actions/100587/2 "2017-09-15T14:10:08Z")

</div>

Well, I suppose I was making this harder on myself than it needed to be. Using basic Java functions did the trick. I can be pretty dense, at times. I'll leave this here in case anyone needs it. Feel free to make suggestions.

```
{
  "script": {
    "source": "return ['hosts' : ctx.payload.aggregations.hosts.buckets.stream().map(b -> [b.key: b.values.value]).collect(Collectors.toList()).join('\\\\n\\\\n').replace('{','').replace('}','').replace('=',' ') ]",
    "lang": "painless"
  }
}
```

---

<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:** [October 13, 2017, 2:10pm UTC](https://discuss.elastic.co/t/stream-list-output-formatting-in-script-for-use-in-watcher-actions/100587/3 "2017-10-13T14:10:09Z")

</div>

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