# Relation between "\_version", "\_seq\_no" and "\_primary\_term"

**URL:** https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647
**Category:** Elasticsearch
**Created:** [May 5, 2019, 4:39am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647 "2019-05-05T04:39:37Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![akshaymaniyar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akshaymaniyar/32/45836_2.png) [@akshaymaniyar](https://discuss.elastic.co/u/akshaymaniyar)
#### Post date: [May 5, 2019, 4:39am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647/1 "2019-05-05T04:39:37Z")

</div>

Does "\_version" of a document will always map to a unique combination of "\_seq\_no" and "\_primary\_term"? Or multiple "\_version" of the doc can have same combination of "\_seq\_no" and "\_primary\_term"?  
Context:  
From ES 7, the index API no longer takes in the version but instead expects \_seq\_no and \_primary\_term to be passed. In our contracts, we were sending the version to our clients and whenever they wanted to update the document they had to send the version back.  
Now since that is no more supported, we were thinking of the following approach:

1. Client gives the version which he wants to edit.
2. We get the current document and match the version with the one provided. If the version matches, we pick the \_seq\_no and \_primary\_term from the current document and issue an edit on the same.  
For the above approach to work, it is essential that every version uniquely maps to \_seq\_no and \_primary\_term

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [May 5, 2019, 4:45am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647/2 "2019-05-05T04:45:16Z")

</div>

I hope that [this comment](https://github.com/elastic/elasticsearch/issues/19269#issuecomment-488598561) addresses your question, particularly this sentence:

> To be clear, the `_version` field continues not to uniquely identify a particular version of a document; if you need to do this then you should move to using the `_seq_no` and `_primary_term` fields.

---

<div class="post-metadata">

### Author: ![akshaymaniyar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akshaymaniyar/32/45836_2.png) [@akshaymaniyar](https://discuss.elastic.co/u/akshaymaniyar)
#### Post date: [May 5, 2019, 5:31am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647/3 "2019-05-05T05:31:03Z")

</div>

Thanks for the quick reply.

So does \_version filed has any significance now? Will it be deprecated in the future versions?

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [May 5, 2019, 6:56am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647/4 "2019-05-05T06:56:35Z")

</div>

The `_version` field is still meaningful for [external versioning](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-versioning).

---

<div class="post-metadata">

### Author: ![akshaymaniyar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akshaymaniyar/32/45836_2.png) [@akshaymaniyar](https://discuss.elastic.co/u/akshaymaniyar)
#### Post date: [May 5, 2019, 8:18am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647/5 "2019-05-05T08:18:18Z")

</div>

Makes sense.  
However should the documentation for internal versioning be updated to state it clearly that internal versioning won't work anymore

[https://www.elastic.co/guide/en/elasticsearch/reference/7.1/docs-index\_.html#\_version\_types](https://www.elastic.co/guide/en/elasticsearch/reference/7.1/docs-index_.html#_version_types)

The doc still says  
`internal` - Only index the document if the given version is identical to the version of the stored document.

Which is not valid anymore. Or is there a way to still issue a write on internal version (if it is acceptable by the developer, even if it doesn't work in corner cases)

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [May 5, 2019, 9:03am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647/6 "2019-05-05T09:03:52Z")

</div>

That's a good point, those docs do indeed look like they need more work. Would you open an issue on GitHub?

---

<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: [June 2, 2019, 9:03am UTC](https://discuss.elastic.co/t/relation-between-version-seq-no-and-primary-term/179647/7 "2019-06-02T09:03:52Z")

</div>

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