# How to use new line '\\n' in a loop

**URL:** <https://discuss.elastic.co/t/how-to-use-new-line-n-in-a-loop/133472>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [May 28, 2018, 7:03am UTC](https://discuss.elastic.co/t/how-to-use-new-line-n-in-a-loop/133472 "2018-05-28T07:03:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addanuj](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@addanuj](https://discuss.elastic.co/u/addanuj)\
**Post date:** [May 28, 2018, 7:03am UTC](https://discuss.elastic.co/t/how-to-use-new-line-n-in-a-loop/133472/1 "2018-05-28T07:03:37Z")

</div>

I have a watch which triggers a alert on following condition " Multiple Virus Detected Alert in last one hour" for simulation i have changed it to 10 sec.

Problem: when i print following  
`"text": "There are {{#ctx.payload.aggregations.host_bucket.buckets}}{{doc_count}} {{key}} {{/ctx.payload.aggregations.host_bucket.buckets}}"`

How to use new line '\n' in a loop ... what would be the correct syntax.  
below is the result right now:

"subject": " Malwarebytes- Multiple Virus Detected Alert in last one hour test 2 ",  
"body": {  
"text": "There are 4401793 MNL12PJ7C2-W7D 135973 VDILUBAPA01-WXV 28043 ALABARBCA01WXL 13476 ALAANDERSC2-W7L 394 RISOKCL-3026927 384 ALALILJMA01-W7L 330 ALAPOOLCH01-W7L 125 DAYWILMOTKXW10 52 ALADAWSJA03-WXL 48 RDP-4164411-W7 40 BWDPATENI03-W7L 40 OKCBIKOBO01WXL 38 BCTLWXMALOCA01 24 BCTLW7SUMKINTE 20 DUBBREEJO01-W0L 19 DAYMCKEONJX-W7D 17 MNL11PQ7C2-W10D 14 BWDKOREIBNA-W7L 12 ALAEUVS001-W7D 11 BCTDALESICM-WXL 9 ALALINGARSX-W7L 8 ILOCD6X132-WXD 8 ILOGG6X132-WXD 8 MNL11D70N2-W10L 7 ILO4D6C862-WXD 6 RDPWOODDA01-WXL 5 ALAPARASR01-W7L 5 BCTLW7SANTMA01A 5 MINLW10-FN2G71 4 ALACHENWX-W7L 4 ALAINJAVI01WRL 4 ALALOANER1-WXL 4 ALAMERRRO01-WXL 4 ALAPFEIFFALWXL 4 ALASTRAK01-WXL 4 ALAWALKERKM-WXL 4 BCTCANNHU01-WXL 4 BCTHILLKY01-WXL 4 BRAMORARE01WXL 4 BWDSOLLSC-W10D 4 DULCHANKE01WXD 4 HBECOOMERKS-WXL 4 OKCBURFMA01-WXL 4 OKCHAUSDA01-WXL 4 TLVHERZEL01W7L 4 VDIBASAKSX-WXV 4 VDIJAYCMA01-WXV 4 VDIKUMAGU01-WXV 4 VDILAKSBH01-WXV 4 VDIMOHAMMRX-WXV 4 VDIVELUNA01-WXV 3 ALAJONESJD-W7D 3 OKCBRADNO01WXL 2 ALAVW10-SA214 2 BCTLW7JAINHX 2 BWDMATHENKD-10L 2 ILO396C862-WXD 2 ILO8M39T92-W7D 2 MNL12BK7C2-W7D 1 ALACLARYCW-W7L 1 ALAFLOJA01WXL 1 ALAMECHSA01-W7L 1 ALANAIKSI01-W7L 1 ALAPALURA01-W7D 1 BCTORDEES01-WXL 1 BZNDOLESHBR-WXL 1 CARHAINOL01-W10 1 EMALUNDGE01-WXL 1 ILO3H6X132-W7D 1 OKCVALEMA01-W7D "  
}

---

<div class="post-metadata">

**Author:** ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)\
**Post date:** [May 31, 2018, 4:42pm UTC](https://discuss.elastic.co/t/how-to-use-new-line-n-in-a-loop/133472/2 "2018-05-31T16:42:08Z")

</div>

Just simply add `\n` anywhere, such as:

```auto
"text": "They are:\n {{#ctx.payload.aggregations.host_bucket.buckets}}{{doc_count}} {{key}} \n{{/ctx.payload.aggregations.host_bucket.buckets}}"

```

---

<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 28, 2018, 4:42pm UTC](https://discuss.elastic.co/t/how-to-use-new-line-n-in-a-loop/133472/3 "2018-06-28T16:42:08Z")

</div>

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