mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Fix dupe detection on upgrade
This commit is contained in:
parent
4766e64c90
commit
021ec0fac4
4 changed files with 18 additions and 3 deletions
|
@ -46,7 +46,9 @@ export const createPersistenceRuleTypeWrapper: CreatePersistenceRuleTypeWrapper
|
|||
body: {
|
||||
query: {
|
||||
ids: {
|
||||
values: alertChunk.map((alert) => alert._id),
|
||||
values: alertChunk
|
||||
.flatMap((alert) => [alert._id, alert._meta?.legacyId])
|
||||
.filter((item) => item != null) as string[],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
|
@ -81,8 +83,9 @@ export const createPersistenceRuleTypeWrapper: CreatePersistenceRuleTypeWrapper
|
|||
}
|
||||
|
||||
const augmentedAlerts = filteredAlerts.map((alert) => {
|
||||
const { _meta, ...rest } = alert;
|
||||
return {
|
||||
...alert,
|
||||
...rest,
|
||||
_source: {
|
||||
[VERSION]: ruleDataClient.kibanaVersion,
|
||||
...commonRuleFields,
|
||||
|
|
|
@ -20,6 +20,9 @@ import { IRuleDataClient } from '../rule_data_client';
|
|||
export type PersistenceAlertService = <T>(
|
||||
alerts: Array<{
|
||||
_id: string;
|
||||
_meta?: {
|
||||
legacyId: string;
|
||||
};
|
||||
_source: T;
|
||||
}>,
|
||||
refresh: boolean | 'wait_for'
|
||||
|
|
|
@ -30,7 +30,7 @@ export const bulkCreateFactory =
|
|||
refreshForBulkCreate: RefreshTypes
|
||||
) =>
|
||||
async <T extends Record<string, unknown>>(
|
||||
wrappedDocs: Array<BaseHit<T>>
|
||||
wrappedDocs: Array<BaseHit<T> & { _meta: { legacyId: string } }>
|
||||
): Promise<GenericBulkCreateResponse<T>> => {
|
||||
if (wrappedDocs.length === 0) {
|
||||
return {
|
||||
|
@ -47,6 +47,7 @@ export const bulkCreateFactory =
|
|||
const { createdAlerts } = await alertWithPersistence(
|
||||
wrappedDocs.map((doc) => ({
|
||||
_id: doc._id,
|
||||
_meta: doc._meta,
|
||||
// `fields` should have already been merged into `doc._source`
|
||||
_source: doc._source,
|
||||
})),
|
||||
|
|
|
@ -37,6 +37,14 @@ export const wrapHitsFactory =
|
|||
return {
|
||||
_id: id,
|
||||
_index: '',
|
||||
_meta: {
|
||||
legacyId: generateId(
|
||||
event._index,
|
||||
event._id,
|
||||
String(event._version),
|
||||
completeRule.alertId
|
||||
),
|
||||
},
|
||||
_source: {
|
||||
...buildBulkBody(
|
||||
spaceId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue