# Concurrent patch updates

**URL:** <https://discuss.elastic.co/t/concurrent-patch-updates/296257>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [February 4, 2022, 7:24am UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257 "2022-02-04T07:24:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![SriAkash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriakash/32/77423_2.png) [@SriAkash](https://discuss.elastic.co/u/SriAkash)\
**Post date:** [February 4, 2022, 7:24am UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/1 "2022-02-04T07:24:57Z")

</div>

Is there a way to handle concurrent patch updates to same document in Elastic App Search?

Its been observed that when two concurrent update statements(patch calls) are sent to Elastic App Search, only changes in one of the API calls gets reflected, however both of them returns success response with no errors.

---

<div class="post-metadata">

**Author:** ![jhonalbert](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jhonalbert](https://discuss.elastic.co/u/jhonalbert)\
**Post date:** [February 4, 2022, 7:34am UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/2 "2022-02-04T07:34:27Z")

</div>

The concurrent update problem is something that can happen when multiple database sessions are permitted to update the same data at the same time which is why it's called the concurrent update problem. Whenever a database user connects to the database, a new session is created.

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [February 4, 2022, 5:13pm UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/3 "2022-02-04T17:13:34Z")

</div>

Hi @SriAkash ,

I think your issue might be one of misunderstanding - App Search does not have "patch" APIs, but full "update" APIs. When you specify a document with an ID that already exists in your engine, you overwrite that document in its entirety. So whichever request is serviced second will win out. You may need to evaluate your architecture, to try to keep two distinct processes/threads from attempting to write to the same ID with different data at the same time.

---

<div class="post-metadata">

**Author:** ![SriAkash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriakash/32/77423_2.png) [@SriAkash](https://discuss.elastic.co/u/SriAkash)\
**Post date:** [February 7, 2022, 8:50am UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/4 "2022-02-07T08:50:05Z")

</div>

Hello @Sean_Story,

App Search "patch" APIs are available at [Partial Update](https://www.elastic.co/guide/en/app-search/7.16/documents.html#documents-partial)

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [February 7, 2022, 8:39pm UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/5 "2022-02-07T20:39:21Z")

</div>

hi @SriAkash

> [@SriAkash](#):
>
> App Search "patch" APIs are available at [Partial Update](https://www.elastic.co/guide/en/app-search/7.16/documents.html#documents-partial)

🤦‍♂️ Well that is embarassing. TIL, thank you for pointing that out.

Let me start over 😅 .

When you send the concurrent patch updates, are you patching the same fields with different values? Or different sets of fields for the same ID, but only one of the patches is getting applied?

---

<div class="post-metadata">

**Author:** ![SriAkash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriakash/32/77423_2.png) [@SriAkash](https://discuss.elastic.co/u/SriAkash)\
**Post date:** [February 8, 2022, 3:35pm UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/6 "2022-02-08T15:35:29Z")

</div>

Hello @Sean_Story ,  
The two patch calls contains different fields. However there are certain fields such as timestamp which is available in both calls but it has same value in both APIs. So, it looks like :  
Request body 1-

```auto
[
    {
        "id": "abc",
        "event_timestamp": "2022-02-01T10:10:24.080750Z",
        "field_a": "value_1"
    }
]

```

Request body 2-

```auto
[
    {
        "id": "abc",
        "event_timestamp": "2022-02-01T10:10:24.080750Z",
        "field_b": "value_2"
    }
]

```

In this case, only one of the patch gets applied.

---

<div class="post-metadata">

**Author:** ![Brian\_McGue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brian_mcgue/32/63366_2.png) [@Brian\_McGue](https://discuss.elastic.co/u/Brian_McGue)\
**Post date:** [February 10, 2022, 11:31pm UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/7 "2022-02-10T23:31:56Z")

</div>

Hi @SriAkash,

I'm looking at the code now and I believe this is a real bug that will need a fix. The App Search Partial Update API looks like it retrieves the current document and reindexes it with the new changes overriding the existing values rather than using the underlying Elasticsearch Partial Update API: [Update API | Elasticsearch Guide [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html).

I will create an internal issue to track this. Unfortunately, I don't have a great workaround at the moment. My apologies.

---

<div class="post-metadata">

**Author:** ![SriAkash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriakash/32/77423_2.png) [@SriAkash](https://discuss.elastic.co/u/SriAkash)\
**Post date:** [February 16, 2022, 1:59pm UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/8 "2022-02-16T13:59:19Z")

</div>

Thanks @Brian_McGue for checking and confirming the bug. Hope it gets fixes soon.

---

<div class="post-metadata">

**Author:** ![jhonalbert](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jhonalbert](https://discuss.elastic.co/u/jhonalbert)\
**Post date:** [March 14, 2022, 10:09am UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/9 "2022-03-14T10:09:41Z")

</div>

Is this issue resoled ?

---

<div class="post-metadata">

**Author:** ![Brian\_McGue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brian_mcgue/32/63366_2.png) [@Brian\_McGue](https://discuss.elastic.co/u/Brian_McGue)\
**Post date:** [March 15, 2022, 11:01pm UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/10 "2022-03-15T23:01:14Z")

</div>

Unfortunately, this has not been resolved yet. I appreciate you asking, though. I'll try to bump this issue with the team.

---

<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:** [April 12, 2022, 11:02pm UTC](https://discuss.elastic.co/t/concurrent-patch-updates/296257/11 "2022-04-12T23:02:06Z")

</div>

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