Bulk ingest example for Elasticsearch

Brand new here. I am working through the example for bulk ingest into elastic search found here 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.

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.



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! :sweat_smile:

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