Reset the version value of a document


I want to reset the version value of a document I read about in this blog on how to:

and at this end it's written:

For most practical use cases, 60 second is enough for the system to catch up and for delayed requests to arrive. If this doesn't work for you, you can change it by setting index.gc_deletes on your index to some other time span.

So if I wait ~ 60 sec after I delete my document the version is set to zero and if I need to reduce this time I need to set gc_deletes to lower value.

I don't know the side effect of reducing the the gc value. So I wonder if there's a dynamic way to call it, like refresh or flush.
Otherwise need to wait one minute, which can be ok for my case as I need to reset the version only in some really rare case.

Here a test case for those who want to reproduce (elastic 6.x):

#Clean all and create a new document

DELETE my_index

PUT my_index/doc/1

#get the version, must return 1

GET my_index/doc/_search
  "version": true

#run again several time to increment the version

PUT my_index/doc/1

Then get (see previous command) the version increase

#delete the document

DELETE my_index/doc/1

#don't wait run one put command then get command and see the version increase, the previous version is kept.

#delete the document and wait 1 minute
#then run put 1 time and get command, the version will be 1

Thanks for any help!


You should not change the time and not rely on this version value being reset due to the reasons you already mentioned in the initial. Maybe you can explain why you rely on this rather internal feature for your application and we can see if there is another way to achieve what you are trying to do.

1 Like

Thank you for the reply,

I use the version value as explain here:

Reset the value is a yagni as for production data I'm not suppose to need it but on dev as we switch branch and data are more corrupted than Sauron, sometime we need to change this value, so far we were dropping the index and re-initialize the counter.

But as explain in the first post I can reset the version and wait ~60 sec so for dev it's enough, so my ask is for information to know if there's another way.
If there's no other way it's ok for me.

Sorry to use only old resources, maybe with the actual elasticsearch version this solution is no more valuable. :older_man:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.