Skip to content

Commit 8170cff

Browse files
authored
[Security Solution][AI Assistant] Handle conflicts during the bulk update (#233288)
## Summary Part of Epic: elastic/security-team#12768 Meta: elastic/security-team#13657 In my [previous PR](#232288), I accidentally removed "retry on conflict" [logic](https://github.com/elastic/kibana/pull/232288/files#r2305375978). These changes add a retry logic on bulk update conflicts. For that we use a `retry_on_conflict` option https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk#operation-bulk-body-application-json-update-retry_on_conflict. The retry count is set to 3 to match previous behaviour. cc @stephmilovic
1 parent be6ca26 commit 8170cff

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ describe('AIAssistantConversationsDataClient', () => {
179179
_id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd',
180180
_index: 'test-index',
181181
_source: true,
182+
retry_on_conflict: 3,
182183
},
183184
},
184185
{

x-pack/solutions/security/plugins/elastic_assistant/server/lib/data_stream/documents_data_writer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,14 @@ export class DocumentsDataWriter implements DocumentsDataWriter {
215215
_id: document.id,
216216
_index: responseToUpdate?.hits.hits.find((c) => c._id === document.id)?._index,
217217
_source: true,
218+
retry_on_conflict: 3,
218219
},
219220
},
220221
getUpdateScript(document, updatedAt),
221222
]);
222223
};
223224

224-
private getDeletedocumentsQuery = async (
225+
private getDeleteDocumentsQuery = async (
225226
documentsToDelete: string[],
226227
authenticatedUser?: AuthenticatedUser
227228
) => {
@@ -274,7 +275,7 @@ export class DocumentsDataWriter implements DocumentsDataWriter {
274275

275276
const documentDeletedBody =
276277
params.documentsToDelete && params.documentsToDelete.length > 0
277-
? await this.getDeletedocumentsQuery(params.documentsToDelete, params.authenticatedUser)
278+
? await this.getDeleteDocumentsQuery(params.documentsToDelete, params.authenticatedUser)
278279
: [];
279280

280281
const documentUpdatedBody =

0 commit comments

Comments
 (0)