# Suggested addition to versioning capabilities

**URL:** https://discuss.elastic.co/t/suggested-addition-to-versioning-capabilities/5779
**Category:** Elasticsearch
**Created:** [November 5, 2011, 10:38am UTC](https://discuss.elastic.co/t/suggested-addition-to-versioning-capabilities/5779 "2011-11-05T10:38:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MarcusLongmuir](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@MarcusLongmuir](https://discuss.elastic.co/u/MarcusLongmuir)
#### Post date: [November 5, 2011, 10:38am UTC](https://discuss.elastic.co/t/suggested-addition-to-versioning-capabilities/5779/1 "2011-11-05T10:38:31Z")

</div>

I'm currently writing a system that can have potentially high contention on a single item and I would like to ensure that the version with the greatest number (version number dictated by another process) is the one that is retained after the contention, even if the save attempts are not in numerical order.

If I have an existing item and I save the following versions:

4  
3  
7  
5  
6

Then I would like 7 to be the version that is retained.

The principle is that if ES receives a version number greater than the current expected ID then skip any that were missed. If it receives a version number less than the current expected ID then ignore it.

There may already be a way to achieve this functionality that I have overlooked, but if not then I would be very appreciative of its inclusion.

Thanks,  
Marcus

---

<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: [November 5, 2011, 10:47am UTC](https://discuss.elastic.co/t/suggested-addition-to-versioning-capabilities/5779/2 "2011-11-05T10:47:04Z")

</div>

Hi Marcus,

it is exactly how versioning work in ES.

Quoted from [http://www.elasticsearch.org/guide/reference/api/index\_.html:](http://www.elasticsearch.org/guide/reference/api/index_.html:)

the system checks to see if the version number passed to the index request  
is greater than or equal to the version of the currently stored document.  
If true, the document will be indexed and the new version number used. If  
the value provided is lower than the stored document’s version number, a  
version conflict will occur and the index operation will fail.

A nice side effect is that there is no need to maintain strict ordering of  
async indexing operations executed a result of changes to a source  
database, as long as version numbers from the source database are used.

---

<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: [November 5, 2011, 10:51am UTC](https://discuss.elastic.co/t/suggested-addition-to-versioning-capabilities/5779/3 "2011-11-05T10:51:37Z")

</div>

On Sat, 2011-11-05 at 03:38 -0700, MarcusLongmuir wrote:

> I'm currently writing a system that can have potentially high contention on a  
> single item and I would like to ensure that the version with the greatest  
> number (version number dictated by another process) is the one that is  
> retained after the contention, even if the save attempts are not in  
> numerical order.

Use version\_type=external:

curl -XPUT '[http://127.0.0.1:9200/foo/bar/1?pretty=1&version=10&version\_type=external](http://127.0.0.1:9200/foo/bar/1?pretty=1&version=10&version_type=external)' -d '  
{  
"foo" : "bar"  
}  
'

clint

---

<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: [November 5, 2011, 10:53am UTC](https://discuss.elastic.co/t/suggested-addition-to-versioning-capabilities/5779/4 "2011-11-05T10:53:53Z")

</div>

Hi Benjamin

> A nice side effect is that there is no need to maintain strict  
> ordering of async indexing operations executed a result of changes to  
> a source database, as long as version numbers from the source database  
> are used.

Note "as long as version numbers from the source database are used"

In other words, if you don't specify version\_type=external, then  
out-of-sync versions will fail

clint

---

<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:49am UTC](https://discuss.elastic.co/t/suggested-addition-to-versioning-capabilities/5779/5 "2017-07-06T03:49:51Z")

</div>


