Simpler bulk api

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?

Hi Konstantinos,

The bulk API documentation 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

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

1 Like

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