I am using elasticsearch and accessing it from C# through the NEST driver. I need to do some concurrency control on the documents I am adding and updating through the NEST driver. Here is a link to the corresponding elasticsearch feature, but I am unable to find any information on how to use document versioning with the NEST driver.
I attempted to set up a mapping, hoping the “_version” property would deserialize from the indexed document (without serializing), but no luck.
Has anyone been able to do what I am trying to do? Is this even possible?
_versionis a meta data attribute that you can access usingresult.DocumentsWithMetaDatathis exposes anIEnumerable<Hit<YourDto>>andHit<YourDto>>has a.Versionproperty.Elasticsearch will automatically increase the version number if none is specified.
You can specify your own expected version when you index see the tests here:
https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Core/Versioning/VersioningTests.cs
From the ES docs i have not been able to find a mention on how to specify the expected version on the
GETandScript UpdateAPI. Will have to dive in deeper to be absolutely sure it’s not needed there.The
op_typecreate mentioned on http://www.elasticsearch.org/blog/2011/02/08/versioning.html is not supported, will also get that in for the next release.