# Simpler bulk api

**URL:** <https://discuss.elastic.co/t/simpler-bulk-api/108579>\
**Category:** Elasticsearch\
**Created:** [November 21, 2017, 3:10pm UTC](https://discuss.elastic.co/t/simpler-bulk-api/108579 "2017-11-21T15:10:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![konstantino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/konstantino/32/24666_2.png) [@konstantino](https://discuss.elastic.co/u/konstantino)\
**Post date:** [November 21, 2017, 3:10pm UTC](https://discuss.elastic.co/t/simpler-bulk-api/108579/1 "2017-11-21T15:10:14Z")

</div>

OK, so \_bulk api over HTTP follows this structure:

POST \_bulk  
{index, type=foo}  
{foo : my data}  
{index, type=foo}  
{foo : my other data}

Would it be possible to still use the bulk api but instead place index and type in the query string?

POST index/type/\_bulk  
{foo : my data}  
{foo : my other data}

is there perhaps another alternative to achieve the same effect so insert multiple data via bulk api without this kind of redundancy?

---

<div class="post-metadata">

**Author:** ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)\
**Post date:** [November 24, 2017, 6:41pm UTC](https://discuss.elastic.co/t/simpler-bulk-api/108579/2 "2017-11-24T18:41:18Z")

</div>

Hi Konstantinos,

The [bulk API documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html#docs-bulk) states that you must provide the structure as below:

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

```

If all your action are targeting the same index and the same type you could simplify the actions informing them in the URL:

```
POST test/doc/_bulk
{ "index" : { "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_id" : "2" } }
{ "create" : { "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1"} }
{ "doc" : {"field2" : "value2"} }

```

You will still need the action line as you may provide other important informations like the ID of the documents and the action (index, delete, update).

Cheers,  
LG

---

<div class="post-metadata">

**Author:** ![konstantino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/konstantino/32/24666_2.png) [@konstantino](https://discuss.elastic.co/u/konstantino)\
**Post date:** [November 24, 2017, 9:17pm UTC](https://discuss.elastic.co/t/simpler-bulk-api/108579/3 "2017-11-24T21:17:20Z")

</div>

Thanks LG!

This could be an opportunity for enhancement here. A simpler form would be to state a default action in the query string which would be applied to every field in the body of the request by default i.e.

> POST test/doc/\_bulk/index  
> { "field1" : "value1" }  
> { "field1" : "value3" }

etc. (assuming an autogenerated \_id)

I'll try coining this on github.

Best regards,

/Costa

---

<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:** [December 22, 2017, 9:17pm UTC](https://discuss.elastic.co/t/simpler-bulk-api/108579/4 "2017-12-22T21:17:38Z")

</div>

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