# Bulk insert file having many json entries into Elasticsearch

**URL:** <https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470>\
**Category:** Elasticsearch\
**Created:** [April 6, 2016, 5:11am UTC](https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470 "2016-04-06T05:11:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Astro-es](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@Astro-es](https://discuss.elastic.co/u/Astro-es)\
**Post date:** [April 6, 2016, 5:11am UTC](https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470/1 "2016-04-06T05:11:57Z")

</div>

Hi,

I just wanted to bulk insert into Elasticsearch. I have a file that has many json entries and looks like:  
{"level":"debug","message":"POST : /info","timestamp":"2016-03-31T08:54:52.236Z"}  
{"level":"debug","message":"POST : /info","timestamp":"2016-03-31T08:54:52.265Z"}  
{"level":"debug","message":"POST : /info","timestamp":"2016-03-31T08:54:52.679Z"}  
{"level":"debug","message":"POST : /info","timestamp":"2016-03-31T08:54:52.242Z"}

I tried inserting this file using \_bulk api and got following error:  
{  
"error" : {  
"root\_cause" : [ {  
"type" : "illegal\_argument\_exception",  
"reason" : "Malformed action/metadata line [1], expected START\_OBJECT or END\_OBJECT but found [VALUE\_STRING]"  
} ],  
"type" : "illegal\_argument\_exception",  
"reason" : "Malformed action/metadata line [1], expected START\_OBJECT or END\_OBJECT but found [VALUE\_STRING]"  
},  
"status" : 400  
}

I could insert docs into ES:  
curl -XPUT localhost:9200/\_bulk --data-binary @shakespeare.json (from docs)

But, how can I insert data mentioned above into Elasticsearch?

Thanks!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 6, 2016, 5:16am UTC](https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470/2 "2016-04-06T05:16:23Z")

</div>

The file need to be properly formatted as a [bulk request](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html), it can not just take a file with one object per line.

---

<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:** [April 6, 2016, 5:33am UTC](https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470/3 "2016-04-06T05:33:46Z")

</div>

You have to respect the BULK format. [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-bulk.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-bulk.html)

```auto
action_and_meta_data\n
optional_source\n
action_and_meta_data\n
optional_source\n
....
action_and_meta_data\n
optional_source\n

```

---

<div class="post-metadata">

**Author:** ![Astro-es](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@Astro-es](https://discuss.elastic.co/u/Astro-es)\
**Post date:** [April 6, 2016, 6:49am UTC](https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470/4 "2016-04-06T06:49:31Z")

</div>

Just got it working by inserting action and metadata \n before every json.

Thanks!

---

<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:** [July 5, 2017, 11:02pm UTC](https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470/5 "2017-07-05T23:02:02Z")

</div>


