"The bulk request must be terminated by a newline [\\n]"

I have found similar questions both here as well as on StackOverflow, but unfortunately none of the answers helped.

I am currently using ElasticSearch 7.0.

I want to make a bulk request to my ElasticSearch server. My JSON file contains information that looks something like this:

{ "index": { "_index": "website", "_id": "link1" }}
{ "label":    "Link1" }

Each line is terminated by an LF line break, and there is also an additional LF line break at the end of the document.

In C#, here is how I make a POST request for my bulk data:

HttpResponseMessage response = await httpClient.PostAsJsonAsync($"http://127.0.0.1:9200/website/_bulk", jsonDocumentContents);

And yet I keep seeing this error message:

{"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}

How can I fix this error?

Add a new line at the end of your content.

4 Likes

I have done that, but still see the same error.

You probably did it wrongly.
May be share your file on gist.github.com so we can inspect it?

Try with CR-LF

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