Concurrent patch updates

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.

2 Likes

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.

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.

Hello @Sean_Story,

App Search "patch" APIs are available at Partial Update

hi @SriAkash

:man_facepalming: Well that is embarassing. TIL, thank you for pointing that out.

Let me start over :sweat_smile: .

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?

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-

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

Request body 2-

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

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

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.

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

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

Is this issue resoled ?

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

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