# Bulk ingest example for Elasticsearch

**URL:** <https://discuss.elastic.co/t/bulk-ingest-example-for-elasticsearch/123944>\
**Category:** Elasticsearch\
**Created:** [March 14, 2018, 3:56pm UTC](https://discuss.elastic.co/t/bulk-ingest-example-for-elasticsearch/123944 "2018-03-14T15:56:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![protzman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/protzman/32/28881_2.png) [@protzman](https://discuss.elastic.co/u/protzman)\
**Post date:** [March 14, 2018, 3:56pm UTC](https://discuss.elastic.co/t/bulk-ingest-example-for-elasticsearch/123944/1 "2018-03-14T15:56:44Z")

</div>

Brand new here. I am working through the example for bulk ingest into elastic search found [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/_exploring_your_data.html) and I cannot seem to get the commands to execute. I have the `accounts.json` file in the directory I am executing the curl commands `curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@accounts.json" curl "localhost:9200/_cat/indices?v"`.

When executed the result is saying that I need a newline after the command `"reason" : "The bulk request must be terminated by a newline [\n]"`. I tried different solutions like adding a `-d` or changing the json to x-ndjson like one of the other bulk ingest tutorials said. As I said I am new enough to not really have an idea of what is going on so any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [March 16, 2018, 8:43pm UTC](https://discuss.elastic.co/t/bulk-ingest-example-for-elasticsearch/123944/2 "2018-03-16T20:43:40Z")

</div>

I think your issue is that you are trying to feed JSON into the Bulk API and that end point expects a data file with all lines (to include the last one) terminated with the \n character. Here is what one of my sample bulk data file looks like:

{ "index" : { "\_index" : "kevinfft24", "\_type" : "\_doc"} }\n  
{ "document" : "Some sample text" }\n

Basically you need two lines in your data file for each document you are inserting, one to specify the action (in this case index), \_index and \_type that you are inserting into and one line that contains the actual data to insert. You could probably just write a script to iterate over your accounts.json to spit the data out into a separate file in the correct format. See the URL below for more info.

Kevin

[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)

---

<div class="post-metadata">

**Author:** ![protzman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/protzman/32/28881_2.png) [@protzman](https://discuss.elastic.co/u/protzman)\
**Post date:** [March 16, 2018, 8:51pm UTC](https://discuss.elastic.co/t/bulk-ingest-example-for-elasticsearch/123944/3 "2018-03-16T20:51:27Z")

</div>

Yeah. Thanks for your reply. I tried to delete this post but it appears you cannot on this forum. Originally I thought the error in the console was referring to the curl command - but alas, after much hair pulling it was referring to the JSON file not having a newline at the end. Sorry to waste your time with the reply but I appreciate it! 😅

---

<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:** [April 13, 2018, 8:51pm UTC](https://discuss.elastic.co/t/bulk-ingest-example-for-elasticsearch/123944/4 "2018-04-13T20:51:45Z")

</div>

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