# Java High Level REST Client - GetRequest sequence number and primary term

**URL:** https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083
**Category:** Elasticsearch
**Created:** [July 31, 2019, 9:43am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083 "2019-07-31T09:43:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![edovac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edovac/32/51310_2.png) [@edovac](https://discuss.elastic.co/u/edovac)
#### Post date: [July 31, 2019, 9:43am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083/1 "2019-07-31T09:43:02Z")

</div>

Hi,  
I'm using elasticsearch version 7.2.0 and implementing in my application the optimistic concurrency control with sequence number and primary term parameters.  
As I understand, before these two parameters were introduiced, optimistic concurrency control was implemented wit hversion parameter.  
So, these sequence number and primary term are meant to replace the version parameter (at least for internal versioning) .

Using Java Highl Lever REST client I've noticed in the code and here in the documentation:  
[https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.2/java-rest-high-document-get.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.2/java-rest-high-document-get.html)  
that the GetRequest api still provides a parameter to use old document version parameter, but not for sequence number and primary term.

I think I maybe have misunderstood the differences betweend the old internal version vs. sequence and primary term.

Is this api incomplete or am I missing something?

---

<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: [July 31, 2019, 4:06pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083/2 "2019-07-31T16:06:25Z")

</div>

The response to a "get" request includes the term and sequence number, and "get" requests are realtime, so as soon as a document has been indexed it will be visible to future gets against every in-sync shard copy. If you subsequently get a different version then it must be a later version.

The usual pattern for optimistic concurrency control is to get the latest version of a document (unconditionally) and then update it (conditionally on it not having changed) and for this you do not need a conditional read.

---

<div class="post-metadata">

### Author: ![edovac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edovac/32/51310_2.png) [@edovac](https://discuss.elastic.co/u/edovac)
#### Post date: [August 1, 2019, 7:10am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083/3 "2019-08-01T07:10:41Z")

</div>

Thanks for the reply, it's clear.

I think I was misleaded by the documentation about version parameter. Seeing that, I was expecting the same behaviour with the new parameters.  
I suppose the "old" version parameter is still there to implement optimistic concurrency control with external versioning, is that right?  
Also, does in this context document versioning and optimistic concurrency control mean the same thing?

---

<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: [August 1, 2019, 7:14am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083/4 "2019-08-01T07:14:15Z")

</div>

> [@edovac](#):
>
> I suppose the "old" version parameter is still there to implement optimistic concurrency control with external versioning, is that right?

Yes, although I must admit I don't fully understand why we support conditional reads for external versioning either. I will ask around.

> [@edovac](#):
>
> Also, does in this context document versioning and optimistic concurrency control mean the same thing?

Yes, pretty much.

---

<div class="post-metadata">

### Author: ![edovac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edovac/32/51310_2.png) [@edovac](https://discuss.elastic.co/u/edovac)
#### Post date: [August 1, 2019, 7:44am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083/5 "2019-08-01T07:44:34Z")

</div>

All clear.  
Thank you very much.

---

<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: [August 29, 2019, 7:44am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-getrequest-sequence-number-and-primary-term/193083/6 "2019-08-29T07:44:46Z")

</div>

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