# Using Bulk API with Update in elasticsearch 0.19.3

**URL:** <https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884>\
**Category:** Elasticsearch\
**Created:** [May 28, 2012, 8:49am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884 "2012-05-28T08:49:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [May 28, 2012, 8:49am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/1 "2012-05-28T08:49:32Z")

</div>

Hi,

Does the update API works with the bulk endpoint in ES? I am not being able  
to make it work. The update thing works separately as follows :

REQUEST  
curl -XPOST '[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)' -d '{ "script" :  
"ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'

RESPONSE  
{"ok":true,"\_index":"lp","\_type":"6","\_id":"66207","\_version":6}

But when using with the bulk API, other actions execute, but not the update.

REQUEST  
curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index" :  
"lp", "\_type" : "6", "\_id" : "66207" } }  
{ "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
{ "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
{ "field1" : "value1" }  
{ "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
{ "field1" : "value1" }  
{}'

RESPONSE  
{"took":31,"items":[{"index":{"\_index":"lp","\_type":"6","\_id":"test1","\_version":29,"ok":true}},{"index":{"\_index":"lp","\_type":"6","\_id":"test2","\_version":15,"ok":true}}]}

There is response for the two index queries, but not for the update query.  
The response shows no error either. What am I doing wrong? This is creating  
a roadblock in our development. Please help.

Thanks and Regards,  
Sujoy.

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [May 28, 2012, 11:30am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/2 "2012-05-28T11:30:32Z")

</div>

Also, if I try to execute only a single update query via bulk API, ActionRequestValidationException[Validation  
Failed: 1: no requests added;] is returned.

REQUEST  
curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index" :  
"lp", "\_type" : "6", "\_id" : "66207" } }  
{ "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
{}'

RESPONSE  
{"error":"ActionRequestValidationException[Validation Failed: 1: no  
requests added;]","status":500}

Does that mean that unlike 'index' or 'delete', update is not a valid  
action for bulk API? Has anyone faced this issue?

Regards,  
Sujoy.

On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:

> Hi,
> 
> Does the update API works with the bulk endpoint in ES? I am not being  
> able to make it work. The update thing works separately as follows :
> 
> REQUEST  
> curl -XPOST '[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)' -d '{ "script" :  
> "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> 
> RESPONSE  
> {"ok":true,"\_index":"lp","\_type":"6","\_id":"66207","\_version":6}
> 
> But when using with the bulk API, other actions execute, but not the  
> update.
> 
> REQUEST  
> curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index" :  
> "lp", "\_type" : "6", "\_id" : "66207" } }  
> { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> { "field1" : "value1" }  
> { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> { "field1" : "value1" }  
> {}'
> 
> RESPONSE
> 
> {"took":31,"items":[{"index":{"\_index":"lp","\_type":"6","\_id":"test1","\_version":29,"ok":true}},{"index":{"\_index":"lp","\_type":"6","\_id":"test2","\_version":15,"ok":true}}]}
> 
> There is response for the two index queries, but not for the update query.  
> The response shows no error either. What am I doing wrong? This is creating  
> a roadblock in our development. Please help.
> 
> Thanks and Regards,  
> Sujoy.

---

<div class="post-metadata">

**Author:** ![Benjamin\_Deveze](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benjamin_deveze/32/1577_2.png) [@Benjamin\_Deveze](https://discuss.elastic.co/u/Benjamin_Deveze)\
**Post date:** [May 28, 2012, 4:52pm UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/3 "2012-05-28T16:52:37Z")

</div>

Bulk API does not support update requests currently, just index and delete.

I think that if you open an issue for it on github it could be added.

On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:

> Also, if I try to execute only a single update query via bulk  
> API, ActionRequestValidationException[Validation Failed: 1: no requests  
> added;] is returned.
> 
> REQUEST  
> curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index" :  
> "lp", "\_type" : "6", "\_id" : "66207" } }  
> { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> {}'
> 
> RESPONSE  
> {"error":"ActionRequestValidationException[Validation Failed: 1: no requests  
> added;]","status":500}
> 
> Does that mean that unlike 'index' or 'delete', update is not a valid action  
> for bulk API? Has anyone faced this issue?
> 
> Regards,  
> Sujoy.
> 
> On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> 
> > Hi,
> > 
> > Does the update API works with the bulk endpoint in ES? I am not being  
> > able to make it work. The update thing works separately as follows :
> > 
> > REQUEST  
> > curl -XPOST '[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)' -d '{ "script" :  
> > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > 
> > RESPONSE  
> > {"ok":true,"\_index":"lp","\_type":"6","\_id":"66207","\_version":6}
> > 
> > But when using with the bulk API, other actions execute, but not the  
> > update.
> > 
> > REQUEST  
> > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index" :  
> > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > { "field1" : "value1" }  
> > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > { "field1" : "value1" }  
> > {}'
> > 
> > RESPONSE
> > 
> > {"took":31,"items":[{"index":{"\_index":"lp","\_type":"6","\_id":"test1","\_version":29,"ok":true}},{"index":{"\_index":"lp","\_type":"6","\_id":"test2","\_version":15,"ok":true}}]}
> > 
> > There is response for the two index queries, but not for the update query.  
> > The response shows no error either. What am I doing wrong? This is creating  
> > a roadblock in our development. Please help.
> > 
> > Thanks and Regards,  
> > Sujoy.

--  
Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [May 29, 2012, 6:58am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/4 "2012-05-29T06:58:40Z")

</div>

Thanks Benjamin.

I have opened an issue for it -

> <https://github.com/elastic/elasticsearch/issues/1985>
>
> this issue is based on the thread at location 
> https://groups.google.com/forum/?…hl=en&fromgroups#!topic/elasticsearch/VCwQoZ1Aj4I
> 
> requesting to allow using update API (using scripts) in bulk via the bulk request API.

Regards,  
Sujoy.

On Monday, May 28, 2012 10:22:37 PM UTC+5:30, Benjamin Devèze wrote:

> Bulk API does not support update requests currently, just index and  
> delete.
> 
> I think that if you open an issue for it on github it could be added.
> 
> On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:
> 
> > Also, if I try to execute only a single update query via bulk  
> > API, ActionRequestValidationException[Validation Failed: 1: no requests  
> > added;] is returned.
> > 
> > REQUEST  
> > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index" :  
> > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > {}'
> > 
> > RESPONSE  
> > {"error":"ActionRequestValidationException[Validation Failed: 1: no  
> > requests  
> > added;]","status":500}
> > 
> > Does that mean that unlike 'index' or 'delete', update is not a valid  
> > action  
> > for bulk API? Has anyone faced this issue?
> > 
> > Regards,  
> > Sujoy.
> > 
> > On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> > 
> > > Hi,
> > > 
> > > Does the update API works with the bulk endpoint in ES? I am not being  
> > > able to make it work. The update thing works separately as follows :
> > > 
> > > REQUEST  
> > > curl -XPOST '[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)' -d '{ "script"  
> > > :  
> > > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > > 
> > > RESPONSE  
> > > {"ok":true,"\_index":"lp","\_type":"6","\_id":"66207","\_version":6}
> > > 
> > > But when using with the bulk API, other actions execute, but not the  
> > > update.
> > > 
> > > REQUEST  
> > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index"  
> > > :  
> > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > > { "field1" : "value1" }  
> > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > > { "field1" : "value1" }  
> > > {}'
> > > 
> > > RESPONSE
> 
> {"took":31,"items":[{"index":{"\_index":"lp","\_type":"6","\_id":"test1","\_version":29,"ok":true}},{"index":{"\_index":"lp","\_type":"6","\_id":"test2","\_version":15,"ok":true}}]}
> 
> > > There is response for the two index queries, but not for the update  
> > > query.  
> > > The response shows no error either. What am I doing wrong? This is  
> > > creating  
> > > a roadblock in our development. Please help.
> > > 
> > > Thanks and Regards,  
> > > Sujoy.
> 
> --  
> Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 29, 2012, 9:51pm UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/5 "2012-05-29T21:51:43Z")

</div>

It makes sense to have a bulk API for update, the tricky bit here is to  
create a nice API design so if one uses the same script, you don't have to  
repeat it for each item.

On Tue, May 29, 2012 at 8:58 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:

> Thanks Benjamin.
> 
> I have opened an issue for it -  
> [using bulk API with update (using scripts) in elasticsearch · Issue #1985 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1985)
> 
> Regards,  
> Sujoy.
> 
> On Monday, May 28, 2012 10:22:37 PM UTC+5:30, Benjamin Devèze wrote:
> 
> > Bulk API does not support update requests currently, just index and  
> > delete.
> > 
> > I think that if you open an issue for it on github it could be added.
> > 
> > On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:
> > 
> > > Also, if I try to execute only a single update query via bulk  
> > > API, **ActionRequestValidationExcepti** on[Validation Failed: 1: no  
> > > requests  
> > > added;] is returned.
> > > 
> > > REQUEST  
> > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index"  
> > > :  
> > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > {}'
> > > 
> > > RESPONSE  
> > > {"error":" **ActionRequestValidationExcepti** on[Validation Failed: 1:  
> > > no requests  
> > > added;]","status":500}
> > > 
> > > Does that mean that unlike 'index' or 'delete', update is not a valid  
> > > action  
> > > for bulk API? Has anyone faced this issue?
> > > 
> > > Regards,  
> > > Sujoy.
> > > 
> > > On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Does the update API works with the bulk endpoint in ES? I am not being  
> > > > able to make it work. The update thing works separately as follows :
> > > > 
> > > > REQUEST  
> > > > curl -XPOST '[http://localhost:9200/lp/6/\*\*66207/\_update](http://localhost:9200/lp/6/**66207/_update)[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)'  
> > > > -d '{ "script" :  
> > > > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > > > 
> > > > RESPONSE  
> > > > {"ok":true,"_index":"lp","_\*\*type":"6","_id":"66207","_\*\*version":6}
> > > > 
> > > > But when using with the bulk API, other actions execute, but not the  
> > > > update.
> > > > 
> > > > REQUEST  
> > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index"  
> > > > :  
> > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > > > { "field1" : "value1" }  
> > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > > > { "field1" : "value1" }  
> > > > {}'
> > > > 
> > > > RESPONSE
> > > > 
> > > > {"took":31,"items":[{"index":{ **"\_index":"lp","_type":"6","_**  
> > > > id":"test1","\_version":29,"ok" **:true}},{"index":{"\_index":"**  
> > > > lp","\_type":"6","\_id":"test2",\*\*"\_version":15,"ok":true}}]}
> > > > 
> > > > There is response for the two index queries, but not for the update  
> > > > query.  
> > > > The response shows no error either. What am I doing wrong? This is  
> > > > creating  
> > > > a roadblock in our development. Please help.
> > > > 
> > > > Thanks and Regards,  
> > > > Sujoy.
> > 
> > --  
> > Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![vinny](https://avatars.discourse-cdn.com/v4/letter/v/b9e5f3/32.png) [@vinny](https://discuss.elastic.co/u/vinny)\
**Post date:** [May 30, 2012, 3:29am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/6 "2012-05-30T03:29:48Z")

</div>

Won't it have to scroll through every item?

I have modified a simple plugin that does bulk updates (  
[https://github.com/agnellvj/bulktag/tree/query](https://github.com/agnellvj/bulktag/tree/query)). It's not perfect but it  
gets the job done. I only need it for term fields so I just do a merge of  
the existing data from ES and the incoming data.

On Tuesday, May 29, 2012 5:51:43 PM UTC-4, kimchy wrote:

> It makes sense to have a bulk API for update, the tricky bit here is to  
> create a nice API design so if one uses the same script, you don't have to  
> repeat it for each item.

---

<div class="post-metadata">

**Author:** ![jagdeep](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jagdeep](https://discuss.elastic.co/u/jagdeep)\
**Post date:** [May 30, 2012, 5:23am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/7 "2012-05-30T05:23:19Z")

</div>

Hey Shay,

Do you have any plan to incorporate this in future release ?

Regards  
Jagdeep

On Wednesday, May 30, 2012 3:21:43 AM UTC+5:30, kimchy wrote:

> It makes sense to have a bulk API for update, the tricky bit here is to  
> create a nice API design so if one uses the same script, you don't have to  
> repeat it for each item.
> 
> On Tue, May 29, 2012 at 8:58 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:
> 
> > Thanks Benjamin.
> > 
> > I have opened an issue for it -  
> > [using bulk API with update (using scripts) in elasticsearch · Issue #1985 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1985)
> > 
> > Regards,  
> > Sujoy.
> > 
> > On Monday, May 28, 2012 10:22:37 PM UTC+5:30, Benjamin Devèze wrote:
> > 
> > > Bulk API does not support update requests currently, just index and  
> > > delete.
> > > 
> > > I think that if you open an issue for it on github it could be added.
> > > 
> > > On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com)  
> > > wrote:
> > > 
> > > > Also, if I try to execute only a single update query via bulk  
> > > > API, **ActionRequestValidationExcepti** on[Validation Failed: 1: no  
> > > > requests  
> > > > added;] is returned.
> > > > 
> > > > REQUEST  
> > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : { "\_index"  
> > > > :  
> > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > {}'
> > > > 
> > > > RESPONSE  
> > > > {"error":" **ActionRequestValidationExcepti** on[Validation Failed: 1:  
> > > > no requests  
> > > > added;]","status":500}
> > > > 
> > > > Does that mean that unlike 'index' or 'delete', update is not a valid  
> > > > action  
> > > > for bulk API? Has anyone faced this issue?
> > > > 
> > > > Regards,  
> > > > Sujoy.
> > > > 
> > > > On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > Does the update API works with the bulk endpoint in ES? I am not  
> > > > > being  
> > > > > able to make it work. The update thing works separately as follows :
> > > > > 
> > > > > REQUEST  
> > > > > curl -XPOST '[http://localhost:9200/lp/6/\*\*66207/\_update](http://localhost:9200/lp/6/**66207/_update)[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)'  
> > > > > -d '{ "script" :  
> > > > > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > > > > 
> > > > > RESPONSE  
> > > > > {"ok":true,"_index":"lp","_\*\*type":"6","_id":"66207","_\*\*version":6}
> > > > > 
> > > > > But when using with the bulk API, other actions execute, but not the  
> > > > > update.
> > > > > 
> > > > > REQUEST  
> > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > "\_index" :  
> > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > > > > { "field1" : "value1" }  
> > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > > > > { "field1" : "value1" }  
> > > > > {}'
> > > > > 
> > > > > RESPONSE
> > > > > 
> > > > > {"took":31,"items":[{"index":{ **"\_index":"lp","_type":"6","_**  
> > > > > id":"test1","\_version":29,"ok" **:true}},{"index":{"\_index":"**  
> > > > > lp","\_type":"6","\_id":"test2",\*\*"\_version":15,"ok":true}}]}
> > > > > 
> > > > > There is response for the two index queries, but not for the update  
> > > > > query.  
> > > > > The response shows no error either. What am I doing wrong? This is  
> > > > > creating  
> > > > > a roadblock in our development. Please help.
> > > > > 
> > > > > Thanks and Regards,  
> > > > > Sujoy.
> > > 
> > > --  
> > > Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [May 30, 2012, 6:04am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/8 "2012-05-30T06:04:51Z")

</div>

Hi Shay,

I have a few bits of suggestions on how the bulk API can be. First of all,  
the data that needs to be passed in bulk API request is not a proper json,  
but a string concatenation of proper jsons separated by newlines. Why it  
can't be a proper json array? That would help in proper creation/  
modification of the data part using jackson or similar json libraries. Also  
that would overcome the current limitation of not having newlines in the  
json data part.

I would like to suggest a bulk API request data format like following ....

{  
"common": {  
"action": {  
"index": {  
"\_index": "lp",  
"\_type": "6"  
}  
},  
"body": {  
"field1": "value1"  
}  
},  
"individual": [  
{  
"action": {  
"update": {  
"\_index": "lp",  
"\_type": "6",  
"\_id": "66207"  
}  
},  
"body": {  
"script": "ctx.\_source.intvalue= ctx.\_source.intvalue + 1"  
}  
},  
{  
"action": {  
"index": {  
"\_index": "lp",  
"\_type": "6",  
"\_id": "test1"  
}  
},  
"body": {  
"field1": "value1"  
}  
},  
{  
"action": {  
"index": {  
"\_index": "lp",  
"\_type": "6",  
"\_id": "test2"  
}  
},  
"body": {  
"field1": "value1"  
}  
},  
{  
"action": {  
"index": {  
"\_index": "lp",  
"\_type": "6",  
"\_id": "id13"  
}  
}  
},  
{  
"action": {  
"index": {  
"\_index": "lp",  
"\_type": "6",  
"\_id": "id14"  
}  
}  
},  
{  
"body": {  
"field2": "test value 2"  
}  
},  
{  
"body": {  
"field2": "test value 3"  
}  
}  
]  
}

The 'common' section contains the default 'action' and 'body', which will  
ONLY be applied if either of these blocks are missing for any element of  
the 'individual' section.

In the above example, the first three elements of the 'individual' section  
are self-complete with both 'action' and 'body' block.  
The 4th and 5th element of the 'individual' block are lacking the 'body'  
block, so the 'body' block from 'common' section will be applied here with  
the specified 'action' blocks.  
Similarly, the 6th and 7th element of the 'individual' section are lacking  
the 'action' block, so the 'action' block from 'common' section will be  
applied here with the specified 'body' blocks.

Makes sense?

Thanks and Regards,  
Sujoy.

On Wednesday, May 30, 2012 10:53:19 AM UTC+5:30, jagdeep wrote:

> Hey Shay,
> 
> Do you have any plan to incorporate this in future release ?
> 
> Regards  
> Jagdeep
> 
> On Wednesday, May 30, 2012 3:21:43 AM UTC+5:30, kimchy wrote:
> 
> > It makes sense to have a bulk API for update, the tricky bit here is to  
> > create a nice API design so if one uses the same script, you don't have to  
> > repeat it for each item.
> > 
> > On Tue, May 29, 2012 at 8:58 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:
> > 
> > > Thanks Benjamin.
> > > 
> > > I have opened an issue for it -  
> > > [using bulk API with update (using scripts) in elasticsearch · Issue #1985 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1985)
> > > 
> > > Regards,  
> > > Sujoy.
> > > 
> > > On Monday, May 28, 2012 10:22:37 PM UTC+5:30, Benjamin Devèze wrote:
> > > 
> > > > Bulk API does not support update requests currently, just index and  
> > > > delete.
> > > > 
> > > > I think that if you open an issue for it on github it could be added.
> > > > 
> > > > On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Also, if I try to execute only a single update query via bulk  
> > > > > API, **ActionRequestValidationExcepti** on[Validation Failed: 1: no  
> > > > > requests  
> > > > > added;] is returned.
> > > > > 
> > > > > REQUEST  
> > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > "\_index" :  
> > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > > {}'
> > > > > 
> > > > > RESPONSE  
> > > > > {"error":" **ActionRequestValidationExcepti** on[Validation Failed: 1:  
> > > > > no requests  
> > > > > added;]","status":500}
> > > > > 
> > > > > Does that mean that unlike 'index' or 'delete', update is not a valid  
> > > > > action  
> > > > > for bulk API? Has anyone faced this issue?
> > > > > 
> > > > > Regards,  
> > > > > Sujoy.
> > > > > 
> > > > > On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > Does the update API works with the bulk endpoint in ES? I am not  
> > > > > > being  
> > > > > > able to make it work. The update thing works separately as follows :
> > > > > > 
> > > > > > REQUEST  
> > > > > > curl -XPOST '[http://localhost:9200/lp/6/\*\*66207/\_update](http://localhost:9200/lp/6/**66207/_update)[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)'  
> > > > > > -d '{ "script" :  
> > > > > > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > > > > > 
> > > > > > RESPONSE  
> > > > > > {"ok":true,"_index":"lp","_\*\*type":"6","_id":"66207","_\*\*version":6}
> > > > 
> > > > > > But when using with the bulk API, other actions execute, but not the  
> > > > > > update.
> > > > > > 
> > > > > > REQUEST  
> > > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > > "\_index" :  
> > > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > > > > > { "field1" : "value1" }  
> > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > > > > > { "field1" : "value1" }  
> > > > > > {}'
> > > > > > 
> > > > > > RESPONSE
> > > > > > 
> > > > > > {"took":31,"items":[{"index":{ **"\_index":"lp","_type":"6","_**  
> > > > > > id":"test1","\_version":29,"ok" **:true}},{"index":{"\_index":"**  
> > > > > > lp","\_type":"6","\_id":"test2",\*\*"\_version":15,"ok":true}}]}
> > > > > > 
> > > > > > There is response for the two index queries, but not for the update  
> > > > > > query.  
> > > > > > The response shows no error either. What am I doing wrong? This is  
> > > > > > creating  
> > > > > > a roadblock in our development. Please help.
> > > > > > 
> > > > > > Thanks and Regards,  
> > > > > > Sujoy.
> > > > 
> > > > --  
> > > > Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [May 30, 2012, 9:04am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/9 "2012-05-30T09:04:16Z")

</div>

Bulk updates, when issued concurrently, are subject to conflict with each  
other, when operating on the same documents at the same time. Maintaining  
update order is significant to get the correct results. To help resolving  
conflicts, a client ID and a client timestamp (tick resolution) could be  
useful, e.g.

{ "action" : { "update" : { "index" : ... }, "client" : "uniqueID",  
"timestamp" : "2012-05-30T10:56:14.123Z" }, ... }

Jörg

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 3, 2012, 9:03am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/10 "2012-06-03T09:03:39Z")

</div>

The common aspect is a nice idea, was thinking about it as well. Note that  
the common section should hold probably the script you want to reference,  
and then each update command will hold specific values.

On Wed, May 30, 2012 at 8:04 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:

> Hi Shay,
> 
> I have a few bits of suggestions on how the bulk API can be. First of all,  
> the data that needs to be passed in bulk API request is not a proper json,  
> but a string concatenation of proper jsons separated by newlines. Why it  
> can't be a proper json array? That would help in proper creation/  
> modification of the data part using jackson or similar json libraries. Also  
> that would overcome the current limitation of not having newlines in the  
> json data part.
> 
> I would like to suggest a bulk API request data format like following ....
> 
> {  
> "common": {  
> "action": {  
> "index": {  
> "\_index": "lp",  
> "\_type": "6"  
> }  
> },  
> "body": {  
> "field1": "value1"  
> }  
> },  
> "individual": [  
> {  
> "action": {  
> "update": {  
> "\_index": "lp",  
> "\_type": "6",  
> "\_id": "66207"  
> }  
> },  
> "body": {  
> "script": "ctx.\_source.intvalue= ctx.\_source.intvalue + 1"  
> }  
> },  
> {  
> "action": {  
> "index": {  
> "\_index": "lp",  
> "\_type": "6",  
> "\_id": "test1"  
> }  
> },  
> "body": {  
> "field1": "value1"  
> }  
> },  
> {  
> "action": {  
> "index": {  
> "\_index": "lp",  
> "\_type": "6",  
> "\_id": "test2"  
> }  
> },  
> "body": {  
> "field1": "value1"  
> }  
> },  
> {  
> "action": {  
> "index": {  
> "\_index": "lp",  
> "\_type": "6",  
> "\_id": "id13"  
> }  
> }  
> },  
> {  
> "action": {  
> "index": {  
> "\_index": "lp",  
> "\_type": "6",  
> "\_id": "id14"  
> }  
> }  
> },  
> {  
> "body": {  
> "field2": "test value 2"  
> }  
> },  
> {  
> "body": {  
> "field2": "test value 3"  
> }  
> }  
> ]  
> }
> 
> The 'common' section contains the default 'action' and 'body', which will  
> ONLY be applied if either of these blocks are missing for any element of  
> the 'individual' section.
> 
> In the above example, the first three elements of the 'individual' section  
> are self-complete with both 'action' and 'body' block.  
> The 4th and 5th element of the 'individual' block are lacking the 'body'  
> block, so the 'body' block from 'common' section will be applied here with  
> the specified 'action' blocks.  
> Similarly, the 6th and 7th element of the 'individual' section are lacking  
> the 'action' block, so the 'action' block from 'common' section will be  
> applied here with the specified 'body' blocks.
> 
> Makes sense?
> 
> Thanks and Regards,  
> Sujoy.
> 
> On Wednesday, May 30, 2012 10:53:19 AM UTC+5:30, jagdeep wrote:
> 
> > Hey Shay,
> > 
> > Do you have any plan to incorporate this in future release ?
> > 
> > Regards  
> > Jagdeep
> > 
> > On Wednesday, May 30, 2012 3:21:43 AM UTC+5:30, kimchy wrote:
> > 
> > > It makes sense to have a bulk API for update, the tricky bit here is to  
> > > create a nice API design so if one uses the same script, you don't have to  
> > > repeat it for each item.
> > > 
> > > On Tue, May 29, 2012 at 8:58 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:
> > > 
> > > > Thanks Benjamin.
> > > > 
> > > > I have opened an issue for it - [https://github.com/](https://github.com/)\*\*  
> > > > elasticsearch/elasticsearch/\*\*issues/1985[https://github.com/elasticsearch/elasticsearch/issues/1985](https://github.com/elasticsearch/elasticsearch/issues/1985)
> > > > 
> > > > Regards,  
> > > > Sujoy.
> > > > 
> > > > On Monday, May 28, 2012 10:22:37 PM UTC+5:30, Benjamin Devèze wrote:
> > > > 
> > > > > Bulk API does not support update requests currently, just index and  
> > > > > delete.
> > > > > 
> > > > > I think that if you open an issue for it on github it could be added.
> > > > > 
> > > > > On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com)  
> > > > > wrote:
> > > > > 
> > > > > > Also, if I try to execute only a single update query via bulk  
> > > > > > API, **ActionRequestValidationEx** cepti\*\*on[Validation Failed: 1:  
> > > > > > no requests  
> > > > > > added;] is returned.
> > > > > > 
> > > > > > REQUEST  
> > > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > > "\_index" :  
> > > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > > > {}'
> > > > > > 
> > > > > > RESPONSE  
> > > > > > {"error":" **ActionRequestValidat** ionExcepti\*\*on[Validation Failed:  
> > > > > > 1: no requests  
> > > > > > added;]","status":500}
> > > > > > 
> > > > > > Does that mean that unlike 'index' or 'delete', update is not a  
> > > > > > valid action  
> > > > > > for bulk API? Has anyone faced this issue?
> > > > > > 
> > > > > > Regards,  
> > > > > > Sujoy.
> > > > > > 
> > > > > > On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > Does the update API works with the bulk endpoint in ES? I am not  
> > > > > > > being  
> > > > > > > able to make it work. The update thing works separately as follows  
> > > > > > > :
> > > > > > > 
> > > > > > > REQUEST  
> > > > > > > curl -XPOST '[http://localhost:9200/lp/6/\*\*66\*\*207/\_update](http://localhost:9200/lp/6/ **66** 207/_update)[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)'  
> > > > > > > -d '{ "script" :  
> > > > > > > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > > > > > > 
> > > > > > > RESPONSE  
> > > > > > > {"ok":true,"_index":"lp","_ **typ** e":"6","_id":"66207","_\*_version_  
> > > > > > > \*":6}
> > > > > > > 
> > > > > > > But when using with the bulk API, other actions execute, but not  
> > > > > > > the  
> > > > > > > update.
> > > > > > > 
> > > > > > > REQUEST  
> > > > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > > > "\_index" :  
> > > > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > > > > > > { "field1" : "value1" }  
> > > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > > > > > > { "field1" : "value1" }  
> > > > > > > {}'
> > > > > > > 
> > > > > > > RESPONSE
> > > > > > > 
> > > > > > > {"took":31,"items":[{"index":{\*\*\*\*"_index":"lp","type":"6","id  
> > > > > > > \*":"test1","\_version":29,"ok"\*:**true}},{"index":{"\_index":"lp"  
> > > > > > > ,"\_type":"6","\_id":"test2",**"_\*\*version":15,"ok":true}}]}
> > > > > > > 
> > > > > > > There is response for the two index queries, but not for the update  
> > > > > > > query.  
> > > > > > > The response shows no error either. What am I doing wrong? This is  
> > > > > > > creating  
> > > > > > > a roadblock in our development. Please help.
> > > > > > > 
> > > > > > > Thanks and Regards,  
> > > > > > > Sujoy.
> > > > > 
> > > > > --  
> > > > > Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [June 3, 2012, 12:54pm UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/11 "2012-06-03T12:54:35Z")

</div>

Hi Shay,

What you suggested can probably be achieved by separating out the "script"  
and "params" blocks of update in the example above. The "body" of an  
"update" block, in "individual" section, will search for the "script" from  
"common" section, if provided with the "params" and not "script".

In short, any missing block in "individual" will be looked upon in  
"common", and the combination thereof will be executed. This "fallback" can  
be at any nested level, and only the missing block will be replaced at the  
most granular level of unavailability.

When things become more complex, it might be needed, however, to restrict  
to a single type of operation in a single bulk request. That would not  
really be a constraint, I feel, but people might think otherwise.

Yes, there might be more of such terminal conditions which needs to be  
handled, but overall. it would be a nice to have feature in ES.

Thanks and Regards,  
Sujoy.

On Sunday, June 3, 2012 2:33:39 PM UTC+5:30, kimchy wrote:

> The common aspect is a nice idea, was thinking about it as well. Note that  
> the common section should hold probably the script you want to reference,  
> and then each update command will hold specific values.
> 
> On Wed, May 30, 2012 at 8:04 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:
> 
> > Hi Shay,
> > 
> > I have a few bits of suggestions on how the bulk API can be. First of  
> > all, the data that needs to be passed in bulk API request is not a proper  
> > json, but a string concatenation of proper jsons separated by newlines. Why  
> > it can't be a proper json array? That would help in proper creation/  
> > modification of the data part using jackson or similar json libraries. Also  
> > that would overcome the current limitation of not having newlines in the  
> > json data part.
> > 
> > I would like to suggest a bulk API request data format like following ....
> > 
> > {  
> > "common": {  
> > "action": {  
> > "index": {  
> > "\_index": "lp",  
> > "\_type": "6"  
> > }  
> > },  
> > "body": {  
> > "field1": "value1"  
> > }  
> > },  
> > "individual": [  
> > {  
> > "action": {  
> > "update": {  
> > "\_index": "lp",  
> > "\_type": "6",  
> > "\_id": "66207"  
> > }  
> > },  
> > "body": {  
> > "script": "ctx.\_source.intvalue= ctx.\_source.intvalue + 1"  
> > }  
> > },  
> > {  
> > "action": {  
> > "index": {  
> > "\_index": "lp",  
> > "\_type": "6",  
> > "\_id": "test1"  
> > }  
> > },  
> > "body": {  
> > "field1": "value1"  
> > }  
> > },  
> > {  
> > "action": {  
> > "index": {  
> > "\_index": "lp",  
> > "\_type": "6",  
> > "\_id": "test2"  
> > }  
> > },  
> > "body": {  
> > "field1": "value1"  
> > }  
> > },  
> > {  
> > "action": {  
> > "index": {  
> > "\_index": "lp",  
> > "\_type": "6",  
> > "\_id": "id13"  
> > }  
> > }  
> > },  
> > {  
> > "action": {  
> > "index": {  
> > "\_index": "lp",  
> > "\_type": "6",  
> > "\_id": "id14"  
> > }  
> > }  
> > },  
> > {  
> > "body": {  
> > "field2": "test value 2"  
> > }  
> > },  
> > {  
> > "body": {  
> > "field2": "test value 3"  
> > }  
> > }  
> > ]  
> > }
> > 
> > The 'common' section contains the default 'action' and 'body', which will  
> > ONLY be applied if either of these blocks are missing for any element of  
> > the 'individual' section.
> > 
> > In the above example, the first three elements of the 'individual'  
> > section are self-complete with both 'action' and 'body' block.  
> > The 4th and 5th element of the 'individual' block are lacking the 'body'  
> > block, so the 'body' block from 'common' section will be applied here with  
> > the specified 'action' blocks.  
> > Similarly, the 6th and 7th element of the 'individual' section are  
> > lacking the 'action' block, so the 'action' block from 'common' section  
> > will be applied here with the specified 'body' blocks.
> > 
> > Makes sense?
> > 
> > Thanks and Regards,  
> > Sujoy.
> > 
> > On Wednesday, May 30, 2012 10:53:19 AM UTC+5:30, jagdeep wrote:
> > 
> > > Hey Shay,
> > > 
> > > Do you have any plan to incorporate this in future release ?
> > > 
> > > Regards  
> > > Jagdeep
> > > 
> > > On Wednesday, May 30, 2012 3:21:43 AM UTC+5:30, kimchy wrote:
> > > 
> > > > It makes sense to have a bulk API for update, the tricky bit here is to  
> > > > create a nice API design so if one uses the same script, you don't have to  
> > > > repeat it for each item.
> > > > 
> > > > On Tue, May 29, 2012 at 8:58 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com)wrote:
> > > > 
> > > > > Thanks Benjamin.
> > > > > 
> > > > > I have opened an issue for it - [https://github.com/](https://github.com/)\*\*  
> > > > > elasticsearch/elasticsearch/\*\*issues/1985[https://github.com/elasticsearch/elasticsearch/issues/1985](https://github.com/elasticsearch/elasticsearch/issues/1985)
> > > > > 
> > > > > Regards,  
> > > > > Sujoy.
> > > > > 
> > > > > On Monday, May 28, 2012 10:22:37 PM UTC+5:30, Benjamin Devèze wrote:
> > > > > 
> > > > > > Bulk API does not support update requests currently, just index and  
> > > > > > delete.
> > > > > > 
> > > > > > I think that if you open an issue for it on github it could be added.
> > > > > > 
> > > > > > On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com)  
> > > > > > wrote:
> > > > > > 
> > > > > > > Also, if I try to execute only a single update query via bulk  
> > > > > > > API, **ActionRequestValidationEx** cepti\*\*on[Validation Failed: 1:  
> > > > > > > no requests  
> > > > > > > added;] is returned.
> > > > > > > 
> > > > > > > REQUEST  
> > > > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > > > "\_index" :  
> > > > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}  
> > > > > > > {}'
> > > > > > > 
> > > > > > > RESPONSE  
> > > > > > > {"error":" **ActionRequestValidat** ionExcepti\*\*on[Validation  
> > > > > > > Failed: 1: no requests  
> > > > > > > added;]","status":500}
> > > > > > > 
> > > > > > > Does that mean that unlike 'index' or 'delete', update is not a  
> > > > > > > valid action  
> > > > > > > for bulk API? Has anyone faced this issue?
> > > > > > > 
> > > > > > > Regards,  
> > > > > > > Sujoy.
> > > > > > > 
> > > > > > > On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > Does the update API works with the bulk endpoint in ES? I am not  
> > > > > > > > being  
> > > > > > > > able to make it work. The update thing works separately as follows  
> > > > > > > > :
> > > > > > > > 
> > > > > > > > REQUEST  
> > > > > > > > curl -XPOST '[http://localhost:9200/lp/6/\*\*66\*\*207/\_update](http://localhost:9200/lp/6/ **66** 207/_update)[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)'  
> > > > > > > > -d '{ "script" :  
> > > > > > > > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > > > > > > > 
> > > > > > > > RESPONSE  
> > > > > > > > {"ok":true,"_index":"lp","_ **typ** e":"6","_id":"66207","_\*\*version  
> > > > > > > > \*\*":6}
> > > > > > > > 
> > > > > > > > But when using with the bulk API, other actions execute, but not  
> > > > > > > > the  
> > > > > > > > update.
> > > > > > > > 
> > > > > > > > REQUEST  
> > > > > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > > > > "\_index" :  
> > > > > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount +  
> > > > > > > > 1"}  
> > > > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > > > > > > > { "field1" : "value1" }  
> > > > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > > > > > > > { "field1" : "value1" }  
> > > > > > > > {}'
> > > > > > > > 
> > > > > > > > RESPONSE
> > > > > > > > 
> > > > > > > > {"took":31,"items":[{"index":{\*\*\*\*"_index":"lp","type":"6","\*\*id  
> > > > > > > > **":"test1","\_version":29,"ok"** :**true}},{"index":{"\_index":"lp"  
> > > > > > > > ,"\_type":"6","\_id":"test2",**"_\*\*version":15,"ok":true}}]}
> > > > > > > > 
> > > > > > > > There is response for the two index queries, but not for the  
> > > > > > > > update query.  
> > > > > > > > The response shows no error either. What am I doing wrong? This is  
> > > > > > > > creating  
> > > > > > > > a roadblock in our development. Please help.
> > > > > > > > 
> > > > > > > > Thanks and Regards,  
> > > > > > > > Sujoy.
> > > > > > 
> > > > > > --  
> > > > > > Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [June 4, 2012, 6:30am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/12 "2012-06-04T06:30:48Z")

</div>

Also, taking in consideration the conflict problem as suggested by Jörg, a  
"timestamp" field can be included (optional? compulsory?) besides the  
"action" and "body" fields of each element of the "individual" block to  
indicate the order of execution, necessary in conflicting cases.

Thanks,  
Sujoy.

On Sunday, June 3, 2012 6:24:35 PM UTC+5:30, Sujoy Sett wrote:

> Hi Shay,
> 
> What you suggested can probably be achieved by separating out the "script"  
> and "params" blocks of update in the example above. The "body" of an  
> "update" block, in "individual" section, will search for the "script" from  
> "common" section, if provided with the "params" and not "script".
> 
> In short, any missing block in "individual" will be looked upon in  
> "common", and the combination thereof will be executed. This "fallback" can  
> be at any nested level, and only the missing block will be replaced at the  
> most granular level of unavailability.
> 
> When things become more complex, it might be needed, however, to restrict  
> to a single type of operation in a single bulk request. That would not  
> really be a constraint, I feel, but people might think otherwise.
> 
> Yes, there might be more of such terminal conditions which needs to be  
> handled, but overall. it would be a nice to have feature in ES.
> 
> Thanks and Regards,  
> Sujoy.
> 
> On Sunday, June 3, 2012 2:33:39 PM UTC+5:30, kimchy wrote:
> 
> > The common aspect is a nice idea, was thinking about it as well. Note  
> > that the common section should hold probably the script you want to  
> > reference, and then each update command will hold specific values.
> > 
> > On Wed, May 30, 2012 at 8:04 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:
> > 
> > > Hi Shay,
> > > 
> > > I have a few bits of suggestions on how the bulk API can be. First of  
> > > all, the data that needs to be passed in bulk API request is not a proper  
> > > json, but a string concatenation of proper jsons separated by newlines. Why  
> > > it can't be a proper json array? That would help in proper creation/  
> > > modification of the data part using jackson or similar json libraries. Also  
> > > that would overcome the current limitation of not having newlines in the  
> > > json data part.
> > > 
> > > I would like to suggest a bulk API request data format like following  
> > > ....
> > > 
> > > {  
> > > "common": {  
> > > "action": {  
> > > "index": {  
> > > "\_index": "lp",  
> > > "\_type": "6"  
> > > }  
> > > },  
> > > "body": {  
> > > "field1": "value1"  
> > > }  
> > > },  
> > > "individual": [  
> > > {  
> > > "action": {  
> > > "update": {  
> > > "\_index": "lp",  
> > > "\_type": "6",  
> > > "\_id": "66207"  
> > > }  
> > > },  
> > > "body": {  
> > > "script": "ctx.\_source.intvalue= ctx.\_source.intvalue +  
> > > 1"  
> > > }  
> > > },  
> > > {  
> > > "action": {  
> > > "index": {  
> > > "\_index": "lp",  
> > > "\_type": "6",  
> > > "\_id": "test1"  
> > > }  
> > > },  
> > > "body": {  
> > > "field1": "value1"  
> > > }  
> > > },  
> > > {  
> > > "action": {  
> > > "index": {  
> > > "\_index": "lp",  
> > > "\_type": "6",  
> > > "\_id": "test2"  
> > > }  
> > > },  
> > > "body": {  
> > > "field1": "value1"  
> > > }  
> > > },  
> > > {  
> > > "action": {  
> > > "index": {  
> > > "\_index": "lp",  
> > > "\_type": "6",  
> > > "\_id": "id13"  
> > > }  
> > > }  
> > > },  
> > > {  
> > > "action": {  
> > > "index": {  
> > > "\_index": "lp",  
> > > "\_type": "6",  
> > > "\_id": "id14"  
> > > }  
> > > }  
> > > },  
> > > {  
> > > "body": {  
> > > "field2": "test value 2"  
> > > }  
> > > },  
> > > {  
> > > "body": {  
> > > "field2": "test value 3"  
> > > }  
> > > }  
> > > ]  
> > > }
> > > 
> > > The 'common' section contains the default 'action' and 'body', which  
> > > will ONLY be applied if either of these blocks are missing for any element  
> > > of the 'individual' section.
> > > 
> > > In the above example, the first three elements of the 'individual'  
> > > section are self-complete with both 'action' and 'body' block.  
> > > The 4th and 5th element of the 'individual' block are lacking the 'body'  
> > > block, so the 'body' block from 'common' section will be applied here with  
> > > the specified 'action' blocks.  
> > > Similarly, the 6th and 7th element of the 'individual' section are  
> > > lacking the 'action' block, so the 'action' block from 'common' section  
> > > will be applied here with the specified 'body' blocks.
> > > 
> > > Makes sense?
> > > 
> > > Thanks and Regards,  
> > > Sujoy.
> > > 
> > > On Wednesday, May 30, 2012 10:53:19 AM UTC+5:30, jagdeep wrote:
> > > 
> > > > Hey Shay,
> > > > 
> > > > Do you have any plan to incorporate this in future release ?
> > > > 
> > > > Regards  
> > > > Jagdeep
> > > > 
> > > > On Wednesday, May 30, 2012 3:21:43 AM UTC+5:30, kimchy wrote:
> > > > 
> > > > > It makes sense to have a bulk API for update, the tricky bit here is  
> > > > > to create a nice API design so if one uses the same script, you don't have  
> > > > > to repeat it for each item.
> > > > > 
> > > > > On Tue, May 29, 2012 at 8:58 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com)wrote:
> > > > > 
> > > > > > Thanks Benjamin.
> > > > > > 
> > > > > > I have opened an issue for it - [https://github.com/](https://github.com/)\*\*  
> > > > > > elasticsearch/elasticsearch/\*\*issues/1985[https://github.com/elasticsearch/elasticsearch/issues/1985](https://github.com/elasticsearch/elasticsearch/issues/1985)
> > > > > > 
> > > > > > Regards,  
> > > > > > Sujoy.
> > > > > > 
> > > > > > On Monday, May 28, 2012 10:22:37 PM UTC+5:30, Benjamin Devèze wrote:
> > > > > > 
> > > > > > > Bulk API does not support update requests currently, just index and  
> > > > > > > delete.
> > > > > > > 
> > > > > > > I think that if you open an issue for it on github it could be  
> > > > > > > added.
> > > > > > > 
> > > > > > > On Mon, May 28, 2012 at 1:30 PM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com)  
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > Also, if I try to execute only a single update query via bulk  
> > > > > > > > API, **ActionRequestValidationEx** cepti\*\*on[Validation Failed: 1:  
> > > > > > > > no requests  
> > > > > > > > added;] is returned.
> > > > > > > > 
> > > > > > > > REQUEST  
> > > > > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > > > > "\_index" :  
> > > > > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount +  
> > > > > > > > 1"}  
> > > > > > > > {}'
> > > > > > > > 
> > > > > > > > RESPONSE  
> > > > > > > > {"error":" **ActionRequestValidat** ionExcepti\*\*on[Validation  
> > > > > > > > Failed: 1: no requests  
> > > > > > > > added;]","status":500}
> > > > > > > > 
> > > > > > > > Does that mean that unlike 'index' or 'delete', update is not a  
> > > > > > > > valid action  
> > > > > > > > for bulk API? Has anyone faced this issue?
> > > > > > > > 
> > > > > > > > Regards,  
> > > > > > > > Sujoy.
> > > > > > > > 
> > > > > > > > On Monday, May 28, 2012 2:19:32 PM UTC+5:30, Sujoy Sett wrote:
> > > > > > > > 
> > > > > > > > > Hi,
> > > > > > > > > 
> > > > > > > > > Does the update API works with the bulk endpoint in ES? I am not  
> > > > > > > > > being  
> > > > > > > > > able to make it work. The update thing works separately as  
> > > > > > > > > follows :
> > > > > > > > > 
> > > > > > > > > REQUEST  
> > > > > > > > > curl -XPOST '[http://localhost:9200/lp/6/\*\*66\*\*207/\_update](http://localhost:9200/lp/6/ **66** 207/_update)[http://localhost:9200/lp/6/66207/\_update](http://localhost:9200/lp/6/66207/_update)'  
> > > > > > > > > -d '{ "script" :  
> > > > > > > > > "ctx.\_source.notesCount = ctx.\_source.notesCount + 1"}'
> > > > > > > > > 
> > > > > > > > > RESPONSE  
> > > > > > > > > {"ok":true,"_index":"lp","_ **typ** e":"6","_id":"66207","_\*\*  
> > > > > > > > > version\*\*":6}
> > > > > > > > > 
> > > > > > > > > But when using with the bulk API, other actions execute, but not  
> > > > > > > > > the  
> > > > > > > > > update.
> > > > > > > > > 
> > > > > > > > > REQUEST  
> > > > > > > > > curl -XPOST '[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)' -d '{ "update" : {  
> > > > > > > > > "\_index" :  
> > > > > > > > > "lp", "\_type" : "6", "\_id" : "66207" } }  
> > > > > > > > > { "script" : "ctx.\_source.notesCount = ctx.\_source.notesCount +  
> > > > > > > > > 1"}  
> > > > > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test1" } }  
> > > > > > > > > { "field1" : "value1" }  
> > > > > > > > > { "index" : { "\_index" : "lp", "\_type" : "6", "\_id" : "test2" } }  
> > > > > > > > > { "field1" : "value1" }  
> > > > > > > > > {}'
> > > > > > > > > 
> > > > > > > > > RESPONSE
> > > > > > > > > 
> > > > > > > > > {"took":31,"items":[{"index":{\*\*\*\*"\_index":"lp","_type":"6","_\*\*  
> > > > > > > > > id\*\*":"test1","\_version":29,"ok"**:true}},{"index":{"\_index":"  
> > > > > > > > > lp"**,"\_type":"6","_id":"test2",\*\*"_\*\*version":15,"ok":true}}]}
> > > > > > > > > 
> > > > > > > > > There is response for the two index queries, but not for the  
> > > > > > > > > update query.  
> > > > > > > > > The response shows no error either. What am I doing wrong? This  
> > > > > > > > > is creating  
> > > > > > > > > a roadblock in our development. Please help.
> > > > > > > > > 
> > > > > > > > > Thanks and Regards,  
> > > > > > > > > Sujoy.
> > > > > > > 
> > > > > > > --  
> > > > > > > Benjamin DEVEZE

---

<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 6, 2017, 3:25am UTC](https://discuss.elastic.co/t/using-bulk-api-with-update-in-elasticsearch-0-19-3/7884/13 "2017-07-06T03:25:47Z")

</div>


