# Bulk Index newline termination error from Elastic cloud

**URL:** <https://discuss.elastic.co/t/bulk-index-newline-termination-error-from-elastic-cloud/146247>\
**Category:** Elasticsearch\
**Created:** [August 27, 2018, 10:27pm UTC](https://discuss.elastic.co/t/bulk-index-newline-termination-error-from-elastic-cloud/146247 "2018-08-27T22:27:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Arndt](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Martin\_Arndt](https://discuss.elastic.co/u/Martin_Arndt)\
**Post date:** [August 27, 2018, 10:27pm UTC](https://discuss.elastic.co/t/bulk-index-newline-termination-error-from-elastic-cloud/146247/1 "2018-08-27T22:27:30Z")

</div>

I am sending content-Type/x-ndjson from AWS Nodejs lambda functions to elastic cloud cluster using https and JSON.Stringify to create message that looks like this

"{ "index" : { "\_index" : "requests-2018-08", "\_type" : "\_doc"}}\n{"timestamp": "2018-08-27T22:29:14.583Z","name":"tour-api-dev-tourcmsAvailability","account":"832247244038","request-id":"a0872a41-aa48-11e8-b5ee-0902424d18a4","msg":"[ERROR] SyntaxError: Unexpected token u in JSON at position 0 at Object.parse (native) at module.exports.handler (/var/task/src/tourcms/availability/get.js:181:27)"}\n{ "index" : { "\_index" : "requests-2018-08", "\_type" : "\_doc"}}\n{"timestamp": "2018-08-27T22:29:14.667Z","name":"tour-api-dev-tourcmsAvailability","account":"832247244038","request-id":"a0872a41-aa48-11e8-b5ee-0902424d18a4","msg":"REPORT RequestId: a0872a41-aa48-11e8-b5ee-0902424d18a4Duration: 348.23 msBilled Duration: 400 ms Memory Size: 128 MBMax Memory Used: 28 MB"}\n"

I am not pretty printing the message with JSON.stringify just sending  
and getting this error:

{  
"error": {  
"root\_cause": [  
{  
"type": "illegal\_argument\_exception",  
"reason": "The bulk request must be terminated by a newline [\n]"  
}  
],  
"type": "illegal\_argument\_exception",  
"reason": "The bulk request must be terminated by a newline [\n]"  
},  
"status": 400  
}

To me it looks like my message is terminated with a newline and when I add one more line break I get a metadata action failure as there is no action on the next blank line.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 28, 2018, 5:34am UTC](https://discuss.elastic.co/t/bulk-index-newline-termination-error-from-elastic-cloud/146247/2 "2018-08-28T05:34:45Z")

</div>

It looks like the meta characters in your payload does not get translated into newlines. If you instead used the [elasticsearch.js](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html) client, it would handle this for you.

---

<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:** [September 25, 2018, 5:34am UTC](https://discuss.elastic.co/t/bulk-index-newline-termination-error-from-elastic-cloud/146247/3 "2018-09-25T05:34:51Z")

</div>

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