Issue with JSON bulk insert "The bulk request must be terminated by a newline [\n]"

I'm trying to bulk upload json to elasticsearch with the below data.
I searched in the forums and found that last line should be newline even if I did that i'm getting the same error.


This is the index i'm using
{"index":{"_index":"momogmail","_type":"email","_id":"1"}}
{"From":"Somesampletext","To":"abc","CC":"cctext","BCC":"bcctext"}

my mapping

You're using the wrong content type. You should be using "Content-Type: application/x-ndjson". Can you see if that resolves the issue?

(By the way, posting screenshots of requests and error messages is not very useful, please copy and paste the actual messages as code-formatted text)

1 Like

Hi,

I tried with application/x-ndjson still getting the same error.

C:\Users\vamsi.srinivas.balla>curl -s -XPOST localhost:9200/momogmail/emails/_bulk?pretty -H "Content-Type: application/x-ndjson" -d @"C:\Users\vamsi.srinivas.balla\Downloads/learnermomo1.json"
{
"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
}

2 Likes

From the notepad++ screenshot, the final line should have LF.

Hi,

Thank you all the issue was resolved when I replaced -d with --data-binary along with application/x-ndjson

Regards,
Vamsi

2 Likes

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