Not able to create a bulk api via curl


(fillic) #1

I am running this commond from curl on elasticsearch 6.0 version

curl -XPOST "localhost:9200/shakespeare/doc/_bulk?pretty" -H "Content-Type:application/json" -d @shakespeare.json

Getting below error.
"reason" : "The bulk request must be terminated by a newline [\n]"

I used the shakespeare.json shared via https://www.elastic.co/guide/en/kibana/current/tutorial-load-dataset.html

I also see mapping needs modification on this page. Any help on how to load sample data. I am completely stuck in here.

If i run this command with --data-binary then it still throws error. What i learnt is -> if i keep index without mapping and then insert, it works... so probably we need to update mapping document in the above said url.


#2

I think the Content-type for the bulk api should be application/x-ndjson..
The link for the documentation is here
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html


(David Pilato) #3

Yes. The guide you used says:

curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/doc/_bulk?pretty' --data-binary @shakespeare_6.0.json

(fillic) #4

Even that was throwing error Saii... issue i observed is the mapping. If i do not take predefined mapping then bulk request do work like a charm. but if i do then its throwing error.


(fillic) #5

Right, the issue here is-> if i define mapping before bulk then this bulk command do throw errors. but if i just run bulk without pre defined mapping then it works like a charm.


(David Pilato) #6

Could you provide a full recreation script as described in

It will help to better understand what you are doing.
Please, try to keep the example as simple as possible.


(fillic) #7

Kindly close this query as i am able to push this data with mapping given on the page. I dont know why it behave weird last time. I did the same step mentione in the page and the query didn't run for a while then i had to cancel the same. But this time i removed the index and ran again and went successfully!

curl -XPOST "localhost:9200/shakespeare/doc/_bulk?pretty" -H "Content-Type:application/json" --data-binary @shakespeare.json


(system) #8

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