# Recursively Returning Results from a Watch, Newline Output

**URL:** <https://discuss.elastic.co/t/recursively-returning-results-from-a-watch-newline-output/118433>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [February 5, 2018, 11:32am UTC](https://discuss.elastic.co/t/recursively-returning-results-from-a-watch-newline-output/118433 "2018-02-05T11:32:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MultiplierMultiplier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/multipliermultiplier/32/25063_2.png) [@MultiplierMultiplier](https://discuss.elastic.co/u/MultiplierMultiplier)\
**Post date:** [February 5, 2018, 11:32am UTC](https://discuss.elastic.co/t/recursively-returning-results-from-a-watch-newline-output/118433/1 "2018-02-05T11:32:09Z")

</div>

Hi guys,

I have managed to get my watch to output all of the usernames when someone fails to logon, they appear one after the other with a space in between, like so:

`"text": "The following user(s) failed to logon: Test Admin TestAdmin User Example`

This is the output I am currently using:

```
 "body": {
          "text": "The following user(s) failed to logon: {{#ctx.payload.hits.hits}} {{_source.target_username}} {{/ctx.payload.hits.hits}}"
        }

```

I would like the output to look something like:

```
The following users failed to logon:
                                                               
                                                               Test
                                                               Admin
                                                               TestAdmin
                                                               Example
                                                               User

```

Or some kind of table format, overall it just needs to be easier to read.

Cheers,

G

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2018, 9:00am UTC](https://discuss.elastic.co/t/recursively-returning-results-from-a-watch-newline-output/118433/2 "2018-02-07T09:00:29Z")

</div>

Hey,

have you tried something like

```auto
{{#ctx.payload.hits.hits}}{{_source.username}}\\n{{/ctx.payload.hits.hits}}

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2018, 9:05am UTC](https://discuss.elastic.co/t/recursively-returning-results-from-a-watch-newline-output/118433/3 "2018-02-07T09:05:38Z")

</div>

or you could use `join` with a transform

```auto
    "actions": {
      "logging": {
        "transform" : {
          "script" : "return ['usernames' : ctx.payload.hits.hits.stream().map(h -> h._source.username).collect(Collectors.toList())]"
        },
        "logging": {
          "text": "{{#join delimiter='\\n'}}ctx.payload.usernames{{/join delimiter='\\n'}}"
        }
      }
    }

```

---

<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:** [March 7, 2018, 9:05am UTC](https://discuss.elastic.co/t/recursively-returning-results-from-a-watch-newline-output/118433/4 "2018-03-07T09:05:40Z")

</div>

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