Elastic.HTTP.post/2 fails with NDJSON body

#20 · closed · 0 comments

View on GitHub ↗

amrfaissal

Hey Ryan, When making HTTP post requests using `Elastic.HTTP.post/2` to Bulk or Multi Search APIs, I get: `You must add a newline \n character` error from Elasticsearch. Looking at the code, I see that just before making an HTTP request you encode the body using `encode_body/1` function which uses Jason. Now when I run `Jason.encode/2` on a binary, it does not return it as is but puts escaping characters all over the place: ``` iex(5)> Jason.encode("{x: 1}\n") {:ok, "\"{x: 1}\\n\""} ``` As you can see, the newline character is being escaped which won't work with Elasticsearch. I'll be more than happy to create a PR for this. Cheers.

Comments