# Bulk updates not respecting \_version

**URL:** <https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134>\
**Category:** Elasticsearch\
**Created:** [October 28, 2013, 5:35am UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134 "2013-10-28T05:35:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Nalya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anand_nalya/32/571_2.png) [@Anand\_Nalya](https://discuss.elastic.co/u/Anand_Nalya)\
**Post date:** [October 28, 2013, 5:35am UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/1 "2013-10-28T05:35:45Z")

</div>

Hi,

I'm trying to do bulk updates on a index with \_version in the conditional  
but ES is updating the document even when there is a version conflict:

{"update":{"\_index":"urls","\_type":"url","\_version":1,"\_id":"ef2ec2fada4c476c0a7d744236ad9551"}}  
{"doc":{"p1":"abc"}}  
{"update":{"\_index":"urls","\_type":"url","\_version":1,"\_id":"5e343487dc6c0ad2b264ffbaffd946c9"}}  
{"doc":{"p2":"xyz"}}

\_version is work properly when I update the documents individually.

Regards,  
Anand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Alina](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Alina](https://discuss.elastic.co/u/Alina)\
**Post date:** [October 28, 2013, 6:55am UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/2 "2013-10-28T06:55:21Z")

</div>

Hello,  
I need the same functionality.  
Also is there a way to access \_version field in script?

Thanks

On Monday, October 28, 2013 7:35:45 AM UTC+2, Anand Nalya wrote:

> Hi,
> 
> I'm trying to do bulk updates on a index with \_version in the conditional  
> but ES is updating the document even when there is a version conflict:
> 
> {"update":{"\_index":"urls","\_type":"url","\_version":1,"\_id":"ef2ec2fada4c476c0a7d744236ad9551"}}  
> {"doc":{"p1":"abc"}}
> 
> {"update":{"\_index":"urls","\_type":"url","\_version":1,"\_id":"5e343487dc6c0ad2b264ffbaffd946c9"}}  
> {"doc":{"p2":"xyz"}}
> 
> \_version is work properly when I update the documents individually.
> 
> Regards,  
> Anand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Anand\_Nalya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anand_nalya/32/571_2.png) [@Anand\_Nalya](https://discuss.elastic.co/u/Anand_Nalya)\
**Post date:** [October 28, 2013, 1:04pm UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/3 "2013-10-28T13:04:26Z")

</div>

Bulk update logic  
@ [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java#L356](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java#L356)  
is similar to that of delete wrt. version, but still its not working.

This is strange.

On Monday, 28 October 2013 12:25:21 UTC+5:30, Alina wrote:

> Hello,  
> I need the same functionality.  
> Also is there a way to access \_version field in script?
> 
> Thanks
> 
> On Monday, October 28, 2013 7:35:45 AM UTC+2, Anand Nalya wrote:
> 
> > Hi,
> > 
> > I'm trying to do bulk updates on a index with \_version in the conditional  
> > but ES is updating the document even when there is a version conflict:
> > 
> > {"update":{"\_index":"urls","\_type":"url","\_version":1,"\_id":"ef2ec2fada4c476c0a7d744236ad9551"}}  
> > {"doc":{"p1":"abc"}}
> > 
> > {"update":{"\_index":"urls","\_type":"url","\_version":1,"\_id":"5e343487dc6c0ad2b264ffbaffd946c9"}}  
> > {"doc":{"p2":"xyz"}}
> > 
> > \_version is work properly when I update the documents individually.
> > 
> > Regards,  
> > Anand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [October 28, 2013, 1:22pm UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/4 "2013-10-28T13:22:59Z")

</div>

You apparently use random \_id's, so can you please show more information  
about how you create a version conflict?

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Anand\_Nalya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anand_nalya/32/571_2.png) [@Anand\_Nalya](https://discuss.elastic.co/u/Anand_Nalya)\
**Post date:** [October 28, 2013, 2:48pm UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/5 "2013-10-28T14:48:14Z")

</div>

Following is another test:

GET [http://localhost:9200/test/type1/1](http://localhost:9200/test/type1/1)

1. {
2. 

```
"_index": "test",

```

3. 

```
"_type": "type1",

```

4. 

```
"_id": "1",

```

5. 

```
"_version": 4,

```

6. 

```
"exists": true,

```

7. 

```
"_source":

```

8. 

```
{

```

9. 

```
    "field1": "value1"

```

10. 

```
}

```

11. }

POST: [http://localhost:9200/\_bulk](http://localhost:9200/_bulk)  
{ "update" : { "\_index" : "test", "\_type" : "type1", "\_id" :  
"1","\_version":1 } }  
{"doc":{ "field1" : "value1" }}

returns

1. {
2. 

```
"took": 60,

```

3. 

```
"items":

```

4. 

```
[

```

5. 

```
    {

```

6. 

```
        "update":

```

7. 

```
        {

```

8. 

```
            "_index": "test",

```

9. 

```
            "_type": "type1",

```

10. 

```
            "_id": "1",

```

11. 

```
            "_version": 5,

```

12. 

```
            "ok": true

```

13. 

```
        }

```

14. 

```
    }

```

15. 

```
]

```

16. }

On 28 October 2013 18:52, [joergprante@gmail.com](mailto:joergprante@gmail.com) [joergprante@gmail.com](mailto:joergprante@gmail.com)wrote:

> You apparently use random \_id's, so can you please show more information  
> about how you create a version conflict?
> 
> Jörg
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/A-Awb64NpTY/unsubscribe](https://groups.google.com/d/topic/elasticsearch/A-Awb64NpTY/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [October 28, 2013, 3:12pm UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/6 "2013-10-28T15:12:04Z")

</div>

Bulk update ignore doc versioning, because update merges old and new  
versions.

Example: [https://gist.github.com/jprante/7198497](https://gist.github.com/jprante/7198497)

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [October 28, 2013, 3:55pm UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/7 "2013-10-28T15:55:44Z")

</div>

Support for the version parameter on update / bulk update is only available  
in master:

> <https://github.com/elastic/elasticsearch/issues/3111>
>
> To reproduce
> 
> \`\`\` sh
> curl -XPOST http://localhost:9200/test/test/1 -d'{
> "fie…ld": "value1"
> }'
> \`\`\`
> 
> The internal version is now 1.
> 
> Now index again:
> 
> \`\`\` sh
> curl -XPOST http://localhost:9200/test/test/1 -d'{
> "field": "value2"
> }'
> \`\`\`
> 
> Internal version is now 2. 
> 
> Try to update using version=1 (should fail)
> 
> \`\`\` sh
> curl -XPOST "http://localhost:9200/test/test/1/\_update?version=1" -d'{
> "doc": { "field": "value3" }
> }'
> \`\`\`
> 
> Which doesn't fail with a version conflict but returns:
> 
> \`\`\` json
> {"ok":true,"\_index":"test","\_type":"test","\_id":"1","\_version":3,"\_previous\_version":2}
> \`\`\`
> 
> PS. The java api's UpdateRequestBuilder doesn't have a setVersion method

On 28 October 2013 16:12, [joergprante@gmail.com](mailto:joergprante@gmail.com) [joergprante@gmail.com](mailto:joergprante@gmail.com)wrote:

> Bulk update ignore doc versioning, because update merges old and new  
> versions.
> 
> Example: [Bulk updates do not conflict, ignore doc versioning · GitHub](https://gist.github.com/jprante/7198497)
> 
> Jörg
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [October 28, 2013, 7:28pm UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/8 "2013-10-28T19:28:38Z")

</div>

Very interesting. I had synthesized my own update by a combination of  
get-by-id, my own additions/deletions to the existing \_source, and then an  
"index" action with the updated \_source along with versioning.

One question about ElasticSearch's "update" action (added since 0.90.1):  
Does this actually update the \_source?

Brian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:10am UTC](https://discuss.elastic.co/t/bulk-updates-not-respecting--version/14134/9 "2017-07-06T02:10:08Z")

</div>


