Bulk request on ElasticSearch returns the message “The bulk request must be terminated by a newline”

I am using ElasticSearch 6.7.0, and I am currently working through its tutorial. Currently, I am stuck at this step, which requires me to download some sample data stored inside a file accounts.json. Here is a small snippet of the file:

{"index":{"_id":"988"}}
{"account_number":988,"balance":17803,"firstname":"Lucy","lastname":"Castro","age":34,"gender":"F","address":"425 Fleet Walk","employer":"Geekfarm","email":"lucycastro@geekfarm.com","city":"Mulino","state":"VA"}
{"index":{"_id":"990"}}
{"account_number":990,"balance":44456,"firstname":"Kelly","lastname":"Steele","age":35,"gender":"M","address":"809 Hoyt Street","employer":"Eschoir","email":"kellysteele@eschoir.com","city":"Stewartville","state":"ID"}
{"index":{"_id":"995"}}
{"account_number":995,"balance":21153,"firstname":"Phelps","lastname":"Parrish","age":25,"gender":"M","address":"666 Miller Place","employer":"Pearlessa","email":"phelpsparrish@pearlessa.com","city":"Brecon","state":"ME"}

The file is saved inside the path C:\Users\Me\Desktop\accounts.json.

I ran the following command, as instructed in the tutorial:

PS C:\Users\Me\Downloads\curl-7.64.1-win64-mingw\bin> .\curl.exe -H
"Content-Type: applicati lhost:9200/bank/_doc/_bulk?pretty&refresh"
--data-binary "C:\Users\Me\Desktop\accounts.json"

I received 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
 }

To fix this, I went to the end of the file and inserted a new line by pressing Enter. However, the same error message appeared when I ran the command again.

How can I fix this issue?

I have fixed the issue.

I moved the accounts.json file to the same directory from which I am running curl.exe, and executed this command:

.\curl.exe -H "Content-Type: applicati
lhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary
"@accounts.json"

This time, the bulk request was successful.

For those facing similar issues, remember to insert a new line at the end of the file by pressing Enter. If that doesn't work, try moving your file into another directory. The error message "The bulk request must be terminated by a newline" can be misleading -- your file might not be malformatted at all; perhaps it simply cannot be located or accessed for various reasons.

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