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

**URL:** <https://discuss.elastic.co/t/bulk-request-on-elasticsearch-returns-the-message-the-bulk-request-must-be-terminated-by-a-newline/175355>\
**Category:** Elasticsearch\
**Created:** [April 4, 2019, 8:42am UTC](https://discuss.elastic.co/t/bulk-request-on-elasticsearch-returns-the-message-the-bulk-request-must-be-terminated-by-a-newline/175355 "2019-04-04T08:42:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miao](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@Miao](https://discuss.elastic.co/u/Miao)\
**Post date:** [April 4, 2019, 8:42am UTC](https://discuss.elastic.co/t/bulk-request-on-elasticsearch-returns-the-message-the-bulk-request-must-be-terminated-by-a-newline/175355/1 "2019-04-04T08:42:31Z")

</div>

I am using `ElasticSearch 6.7.0`, and I am currently working through its tutorial. Currently, I am stuck at [this step](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-explore-data.html), which requires me to [download](https://github.com/elastic/elasticsearch/blob/master/docs/src/test/resources/accounts.json?raw=true) 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](mailto:Walk%22,%22employer%22:%22Geekfarm%22,%22email%22:%22lucycastro@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](mailto:Street%22,%22employer%22:%22Eschoir%22,%22email%22:%22kellysteele@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](mailto:Place%22,%22employer%22:%22Pearlessa%22,%22email%22:%22phelpsparrish@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?

---

<div class="post-metadata">

**Author:** ![Miao](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@Miao](https://discuss.elastic.co/u/Miao)\
**Post date:** [April 4, 2019, 9:03am UTC](https://discuss.elastic.co/t/bulk-request-on-elasticsearch-returns-the-message-the-bulk-request-must-be-terminated-by-a-newline/175355/2 "2019-04-04T09:03:34Z")

</div>

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.

---

<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:** [May 2, 2019, 9:03am UTC](https://discuss.elastic.co/t/bulk-request-on-elasticsearch-returns-the-message-the-bulk-request-must-be-terminated-by-a-newline/175355/3 "2019-05-02T09:03:57Z")

</div>

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