Skip to content

Commit

Permalink
make the change to do partial updates instead of re-index
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed Aug 31, 2023
1 parent f00c4e5 commit 4e916f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 8 additions & 4 deletions x-pack/plugins/alerting/server/alerts_client/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export class AlertsClient<
this.fetchedAlerts.primaryTerm[alert.kibana.alert.uuid],
this.isUsingDataStreams()
),
alert,
getBulkDocument(this.fetchedAlerts.indices[alert.kibana.alert.uuid], alert),
])
);

Expand Down Expand Up @@ -419,6 +419,12 @@ export class AlertsClient<
}
}

function getBulkDocument(index: string | null | undefined, alert: Alert & AlertData) {
// if index provided, must be an update, so wrap in a { doc: {} }
if (index) return { doc: alert };
return alert;
}

function getBulkMeta(
uuid: string,
index: string | undefined,
Expand All @@ -429,11 +435,9 @@ export class AlertsClient<
if (index && seqNo != null && primaryTerm != null) {
return {
// this code will change to use update, and not the if_* fields
index: {
update: {
_id: uuid,
_index: index,
if_seq_no: seqNo,
if_primary_term: primaryTerm,
require_alias: false,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,9 @@ export const createLifecycleExecutor =
indexName
? {
// this code will change to use update, and not the if_* fields
index: {
update: {
_id: event[ALERT_UUID]!,
_index: indexName,
if_seq_no: seqNo,
if_primary_term: primaryTerm,
require_alias: false,
},
}
Expand All @@ -367,7 +365,8 @@ export const createLifecycleExecutor =
_id: event[ALERT_UUID]!,
},
},
event,
// if index provided, must be an update, so wrap in a { doc: {} }
...(indexName ? { doc: event } : event),
]),
refresh: 'wait_for',
});
Expand Down

0 comments on commit 4e916f6

Please sign in to comment.