diff --git a/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts b/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts index 06f4408a517e5..af6ed961f92a2 100644 --- a/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts +++ b/x-pack/plugins/alerting/server/alerts_client/alerts_client.ts @@ -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), ]) ); @@ -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, @@ -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, }, }; diff --git a/x-pack/plugins/rule_registry/server/utils/create_lifecycle_executor.ts b/x-pack/plugins/rule_registry/server/utils/create_lifecycle_executor.ts index da685bdeaebc3..70e91627d7936 100644 --- a/x-pack/plugins/rule_registry/server/utils/create_lifecycle_executor.ts +++ b/x-pack/plugins/rule_registry/server/utils/create_lifecycle_executor.ts @@ -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, }, } @@ -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', });