# Version priority

**URL:** https://discuss.elastic.co/t/version-priority/7387
**Category:** Elasticsearch
**Created:** [April 18, 2012, 4:16pm UTC](https://discuss.elastic.co/t/version-priority/7387 "2012-04-18T16:16:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Oren\_Mazor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oren_mazor/32/2903_2.png) [@Oren\_Mazor](https://discuss.elastic.co/u/Oren_Mazor)
#### Post date: [April 18, 2012, 4:16pm UTC](https://discuss.elastic.co/t/version-priority/7387/1 "2012-04-18T16:16:24Z")

</div>

Hey folks,

I have a queue feeding a bunch of workers that are feeding into ES  
with bulk index requests. In many cases, we create a document (which  
goes into the queue) and then immediately update it.

Before the multiple workers, this was not a problem. but now we have a  
race condition where the updated version of the document is actually  
overwritten by the _earlier_ version of the document.

For example, if the first version of the doc is: {"a":0} and the  
second is {"a":1}, sometimes the second version is inserted first,  
which means that the latest version of the doc is out of date.

is there any way to set priority on fields?

I'm looking into rearchitecting my workers, as well.

---

<div class="post-metadata">

### Author: ![Oren\_Mazor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oren_mazor/32/2903_2.png) [@Oren\_Mazor](https://discuss.elastic.co/u/Oren_Mazor)
#### Post date: [April 18, 2012, 4:23pm UTC](https://discuss.elastic.co/t/version-priority/7387/2 "2012-04-18T16:23:14Z")

</div>

actually, is it possible to edit an old version? the docs aren't too  
clear. I think I get a 409?

I could change my workers to make sure that {"a":1} was always written  
to version=1? that way I make sure 1\>0 in terms of "priority".

On Apr 18, 12:16 pm, Oren Mazor [oren.ma...@gmail.com](mailto:oren.ma...@gmail.com) wrote:

> Hey folks,
> 
> I have a queue feeding a bunch of workers that are feeding into ES  
> with bulk index requests. In many cases, we create a document (which  
> goes into the queue) and then immediately update it.
> 
> Before the multiple workers, this was not a problem. but now we have a  
> race condition where the updated version of the document is actually  
> overwritten by the _earlier_ version of the document.
> 
> For example, if the first version of the doc is: {"a":0} and the  
> second is {"a":1}, sometimes the second version is inserted first,  
> which means that the latest version of the doc is out of date.
> 
> is there any way to set priority on fields?
> 
> I'm looking into rearchitecting my workers, as well.

---

<div class="post-metadata">

### Author: ![Paul\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_smith/32/1323_2.png) [@Paul\_Smith](https://discuss.elastic.co/u/Paul_Smith)
#### Post date: [April 18, 2012, 10:04pm UTC](https://discuss.elastic.co/t/version-priority/7387/3 "2012-04-18T22:04:03Z")

</div>

Do you use the VersionType.EXTERNAL at all? Since you have a field of your  
own data that is the version, you could set the version Property to be your  
domain specific version instead of relying on ES's inbuilt versioning then  
when the 1st version tries to overwrite the 2nd, you'll get a rejection  
(VersionConflictException) which you can just swallow (though the exception  
handling makes it a bit messy, since you only want to swallow this one  
type, not other exceptions).

On 19 April 2012 02:23, Oren Mazor [oren.mazor@gmail.com](mailto:oren.mazor@gmail.com) wrote:

> actually, is it possible to edit an old version? the docs aren't too  
> clear. I think I get a 409?
> 
> I could change my workers to make sure that {"a":1} was always written  
> to version=1? that way I make sure 1\>0 in terms of "priority".
> 
> On Apr 18, 12:16 pm, Oren Mazor [oren.ma...@gmail.com](mailto:oren.ma...@gmail.com) wrote:
> 
> > Hey folks,
> > 
> > I have a queue feeding a bunch of workers that are feeding into ES  
> > with bulk index requests. In many cases, we create a document (which  
> > goes into the queue) and then immediately update it.
> > 
> > Before the multiple workers, this was not a problem. but now we have a  
> > race condition where the updated version of the document is actually  
> > overwritten by the _earlier_ version of the document.
> > 
> > For example, if the first version of the doc is: {"a":0} and the  
> > second is {"a":1}, sometimes the second version is inserted first,  
> > which means that the latest version of the doc is out of date.
> > 
> > is there any way to set priority on fields?
> > 
> > I'm looking into rearchitecting my workers, as well.

---

<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: [April 19, 2012, 2:59pm UTC](https://discuss.elastic.co/t/version-priority/7387/4 "2012-04-19T14:59:00Z")

</div>

You can use versioning to solve this, yes. Or, if its a case of knowing  
that you expect to always create a doc in one case, and update a doc in the  
second, you can set the create flag on the index operation, which will fail  
if the document already exists.

On Wed, Apr 18, 2012 at 7:23 PM, Oren Mazor [oren.mazor@gmail.com](mailto:oren.mazor@gmail.com) wrote:

> actually, is it possible to edit an old version? the docs aren't too  
> clear. I think I get a 409?
> 
> I could change my workers to make sure that {"a":1} was always written  
> to version=1? that way I make sure 1\>0 in terms of "priority".
> 
> On Apr 18, 12:16 pm, Oren Mazor [oren.ma...@gmail.com](mailto:oren.ma...@gmail.com) wrote:
> 
> > Hey folks,
> > 
> > I have a queue feeding a bunch of workers that are feeding into ES  
> > with bulk index requests. In many cases, we create a document (which  
> > goes into the queue) and then immediately update it.
> > 
> > Before the multiple workers, this was not a problem. but now we have a  
> > race condition where the updated version of the document is actually  
> > overwritten by the _earlier_ version of the document.
> > 
> > For example, if the first version of the doc is: {"a":0} and the  
> > second is {"a":1}, sometimes the second version is inserted first,  
> > which means that the latest version of the doc is out of date.
> > 
> > is there any way to set priority on fields?
> > 
> > I'm looking into rearchitecting my workers, as well.

---

<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:31am UTC](https://discuss.elastic.co/t/version-priority/7387/5 "2017-07-06T03:31:53Z")

</div>


