# Custom sequence numbers for partial updates

**URL:** <https://discuss.elastic.co/t/custom-sequence-numbers-for-partial-updates/220459>\
**Category:** Elasticsearch\
**Created:** [February 21, 2020, 10:03pm UTC](https://discuss.elastic.co/t/custom-sequence-numbers-for-partial-updates/220459 "2020-02-21T22:03:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shreedhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shreedhan/32/46350_2.png) [@shreedhan](https://discuss.elastic.co/u/shreedhan)\
**Post date:** [February 21, 2020, 10:03pm UTC](https://discuss.elastic.co/t/custom-sequence-numbers-for-partial-updates/220459/1 "2020-02-21T22:03:04Z")

</div>

Hi,

I'm reading about partial updates and found that we cannot use external version with partial updates. However, I see that ES has introduced `seq_no` and `primary_term` for concurrency control. I see that `seq_no` is automatically incremented with every change but I cannot set it myself. Is there a way to set custom value for `seq_no` and/or `primary_term` for partial updates?

Thanks,  
Shreedhan

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 24, 2020, 9:09am UTC](https://discuss.elastic.co/t/custom-sequence-numbers-for-partial-updates/220459/2 "2020-02-24T09:09:10Z")

</div>

The update API supports `if_seq_no` and `if_primary_term` parameters for optimistic concurrency control. See [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html)

Is. that what you are after?

---

<div class="post-metadata">

**Author:** ![shreedhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shreedhan/32/46350_2.png) [@shreedhan](https://discuss.elastic.co/u/shreedhan)\
**Post date:** [February 24, 2020, 7:52pm UTC](https://discuss.elastic.co/t/custom-sequence-numbers-for-partial-updates/220459/3 "2020-02-24T19:52:07Z")

</div>

Thanks for the reply Alexander. I have looked at the Update API which supports both `if_seq_no` and `if_primary_term`, however, it appears that Elasticsearch sets these values and as a user we don't have an option to update these values. For instance, let's say this is what I get for a `GET` request.

```
GET localhost:9200/test/test/abcd/
{
  "_index": "test",
  "_type": "test",
  "_id": "abcd",
  "_version": 50,
  "_seq_no": 10,
  "_primary_term": 1,
  "found": true,
  "_source": {
    ....
   }
}

```

For the update API, I have to set `if_seq_no` to 10 and `_primary_term` to 1, otherwise I get a `version_conflict_engine_exception`. Note that I'm using `external_version` too, which I cannot use for partial update.

However, I want to send my custom `seq_no`. Let's say I want both `seq_no` and `version` to be the same.

```
POST localhost:9200/test/test/abcd/_update?if_seq_no=50&if_primary_term=1
{
	"doc": {
		"name": "test"
	}
}

```

This request also fails with `version_conflict_engine_exception`. I was wondering if we can supply external version for `seq_no` and/or `primary_term`.

Thanks,  
Shreedhan

---

<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:** [March 23, 2020, 7:52pm UTC](https://discuss.elastic.co/t/custom-sequence-numbers-for-partial-updates/220459/4 "2020-03-23T19:52:17Z")

</div>

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