Not able to create a bulk api via curl

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

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.

I think the Content-type for the bulk api should be application/x-ndjson..
The link for the documentation is here

1 Like

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

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.

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.

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.

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

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