# Not able to create a bulk api via curl

**URL:** <https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333>\
**Category:** Elasticsearch\
**Created:** [December 27, 2017, 3:14pm UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333 "2017-12-27T15:14:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fillic2002](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@fillic2002](https://discuss.elastic.co/u/fillic2002)\
**Post date:** [December 27, 2017, 3:14pm UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/1 "2017-12-27T15:14:51Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![saii](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@saii](https://discuss.elastic.co/u/saii)\
**Post date:** [December 27, 2017, 3:20pm UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/2 "2017-12-27T15:20:32Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 27, 2017, 5:20pm UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/3 "2017-12-27T17:20:00Z")

</div>

Yes. [The guide you used](https://www.elastic.co/guide/en/kibana/current/tutorial-load-dataset.html) says:

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

```

---

<div class="post-metadata">

**Author:** ![fillic2002](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@fillic2002](https://discuss.elastic.co/u/fillic2002)\
**Post date:** [December 28, 2017, 8:07am UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/4 "2017-12-28T08:07:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fillic2002](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@fillic2002](https://discuss.elastic.co/u/fillic2002)\
**Post date:** [December 28, 2017, 8:09am UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/5 "2017-12-28T08:09:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 28, 2017, 8:23am UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/6 "2017-12-28T08:23:16Z")

</div>

Could you provide a full recreation script as described in

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

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

---

<div class="post-metadata">

**Author:** ![fillic2002](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@fillic2002](https://discuss.elastic.co/u/fillic2002)\
**Post date:** [January 2, 2018, 10:34am UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/7 "2018-01-02T10:34:22Z")

</div>

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

---

<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:** [January 30, 2018, 10:34am UTC](https://discuss.elastic.co/t/not-able-to-create-a-bulk-api-via-curl/113333/8 "2018-01-30T10:34:46Z")

</div>

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