# Concatenate fields and add newlines

**URL:** <https://discuss.elastic.co/t/concatenate-fields-and-add-newlines/134722>\
**Category:** Kibana\
**Created:** [June 6, 2018, 4:48am UTC](https://discuss.elastic.co/t/concatenate-fields-and-add-newlines/134722 "2018-06-06T04:48:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ottadini](https://avatars.discourse-cdn.com/v4/letter/o/b19c9b/32.png) [@ottadini](https://discuss.elastic.co/u/ottadini)\
**Post date:** [June 6, 2018, 4:48am UTC](https://discuss.elastic.co/t/concatenate-fields-and-add-newlines/134722/1 "2018-06-06T04:48:27Z")

</div>

I want to combine several fields in Kibana's scripted fields editor using painless. I've got the following, but the field displays in Kibana's Discover interface with the literal \n rather than with a new line:

`doc['field1'].value + '\\n' + doc['field2'].value`

Secondary question: how do I check if doc['somefield'].value has a value before i include it?

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [June 6, 2018, 3:54pm UTC](https://discuss.elastic.co/t/concatenate-fields-and-add-newlines/134722/2 "2018-06-06T15:54:18Z")

</div>

You could use the [elvis](https://www.elastic.co/guide/en/elasticsearch/painless/current/_operators.html#_elvis) operator to do something only if the value is provided.

I do not think you can display scripted field results with newlines. In kibana, scripted field results are rendered as text strings so newlines or html will just be displayed as raw text without any formatting applied.

---

<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:** [July 4, 2018, 3:54pm UTC](https://discuss.elastic.co/t/concatenate-fields-and-add-newlines/134722/3 "2018-07-04T15:54:19Z")

</div>

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