# Version numbers and deletes

**URL:** <https://discuss.elastic.co/t/version-numbers-and-deletes/8062>\
**Category:** Elasticsearch\
**Created:** [June 12, 2012, 4:30pm UTC](https://discuss.elastic.co/t/version-numbers-and-deletes/8062 "2012-06-12T16:30:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davie](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@davie](https://discuss.elastic.co/u/davie)\
**Post date:** [June 12, 2012, 4:30pm UTC](https://discuss.elastic.co/t/version-numbers-and-deletes/8062/1 "2012-06-12T16:30:42Z")

</div>

Hi,  
I'm trying to figure out what the behavior of version numbers is on  
deletes.  
We have a test environment where data is copied from a production database  
regularly, so we want:  
Document copied into test environment, version 1, indexed into ES.  
Updatedin test environment, version 2, indexed  
…  
Document refreshed from production environment, back to version 1.  
We want this then to be reindexed, so we try deleting that document, then  
reindexing it, but get a version conflict exception with current version 2,  
provided 2.

It looks like the delete request is incrementing the (VersionType.EXTERNAL)  
version number.  
Is this correct, and if so is there a way to delete a document and reset  
the version number (without deleting the whole index)?

Thanks,  
Davie

---

<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:** [June 12, 2012, 10:46pm UTC](https://discuss.elastic.co/t/version-numbers-and-deletes/8062/2 "2012-06-12T22:46:39Z")

</div>

We ran into a similar issue. The trick is looking at the code that you have  
to provide the original version # in the delete call as well otherwise the  
delete triggers the default internal versioning behavior and increments the  
number.

Maybe try a GET on the item to get the current version before a delete  
(hard for bulk though mate with multi get and bulk delete it might perform  
ok)

Paul

On Wednesday, 13 June 2012, Davie Moston wrote:

> Hi,  
> I'm trying to figure out what the behavior of version numbers is on  
> deletes.  
> We have a test environment where data is copied from a production database  
> regularly, so we want:  
> Document copied into test environment, version 1, indexed into ES.  
> Updatedin test environment, version 2, indexed  
> …  
> Document refreshed from production environment, back to version 1.  
> We want this then to be reindexed, so we try deleting that document, then  
> reindexing it, but get a version conflict exception with current version 2,  
> provided 2.
> 
> It looks like the delete request is incrementing the  
> (VersionType.EXTERNAL) version number.  
> Is this correct, and if so is there a way to delete a document and reset  
> the version number (without deleting the whole index)?
> 
> Thanks,  
> Davie

---

<div class="post-metadata">

**Author:** ![davie](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@davie](https://discuss.elastic.co/u/davie)\
**Post date:** [June 13, 2012, 9:37am UTC](https://discuss.elastic.co/t/version-numbers-and-deletes/8062/3 "2012-06-13T09:37:35Z")

</div>

Thanks for the suggestion.

I've tried setting the version number in the delete call, but this seems to result in the delete failing with version conflict exception if the version number is less or equal to the current version in ES.  
It only succeeds if the version number is higher, which makes sense for optimistic locking, but I want to delete all knowledge of this document and start again.

Is there a way to delete and reset the version number for an id?

We ran into a similar issue. The trick is looking at the code that you have to provide the original version # in the delete call as well otherwise the delete triggers the default internal versioning behavior and increments the number.

Maybe try a GET on the item to get the current version before a delete  
(hard for bulk though mate with multi get and bulk delete it might perform  
ok)

Paul

On Wednesday, 13 June 2012, Davie Moston wrote:

> Hi,  
> I'm trying to figure out what the behavior of version numbers is on  
> deletes.  
> We have a test environment where data is copied from a production database  
> regularly, so we want:  
> Document copied into test environment, version 1, indexed into ES.  
> Updatedin test environment, version 2, indexed  
> …  
> Document refreshed from production environment, back to version 1.  
> We want this then to be reindexed, so we try deleting that document, then  
> reindexing it, but get a version conflict exception with current version 2,  
> provided 2.
> 
> It looks like the delete request is incrementing the  
> (VersionType.EXTERNAL) version number.  
> Is this correct, and if so is there a way to delete a document and reset  
> the version number (without deleting the whole index)?
> 
> Thanks,  
> Davie

---

<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:24am UTC](https://discuss.elastic.co/t/version-numbers-and-deletes/8062/4 "2017-07-06T03:24:40Z")

</div>


