From cdfd72f8794992b71b97e94958a7d26f696ecac7 Mon Sep 17 00:00:00 2001 From: FrankHassanabad Date: Sat, 12 Feb 2022 13:16:10 -0700 Subject: [PATCH] Fixes issues from merge with new ES client calls --- .../security_solution/server/usage/queries/get_alerts.ts | 7 ++++--- .../server/usage/queries/utils/fetch_hits_with_pit.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/server/usage/queries/get_alerts.ts b/x-pack/plugins/security_solution/server/usage/queries/get_alerts.ts index 1514760b0b251..4c0946242b005 100644 --- a/x-pack/plugins/security_solution/server/usage/queries/get_alerts.ts +++ b/x-pack/plugins/security_solution/server/usage/queries/get_alerts.ts @@ -11,6 +11,7 @@ import type { SearchRequest, } from '@elastic/elasticsearch/lib/api/types'; import type { ElasticsearchClient, Logger } from 'kibana/server'; +import { ALERT_RULE_UUID } from '@kbn/rule-data-utils'; import type { AlertBucket, AlertAggs } from '../types'; export interface GetAlertsOptions { @@ -37,7 +38,7 @@ export const getAlerts = async ({ index: signalsIndex, keep_alive: keepAlive, }) - ).body.id; + ).id; let after: AggregationsCompositeAggregation['after']; let buckets: AlertBucket[] = []; @@ -52,7 +53,7 @@ export const getAlerts = async ({ { detectionAlerts: { terms: { - field: 'kibana.alert.rule.uuid', + field: ALERT_RULE_UUID, }, }, }, @@ -83,7 +84,7 @@ export const getAlerts = async ({ logger.debug( `Getting alerts with point in time (PIT) query: ${JSON.stringify(ruleSearchOptions)}` ); - const { body } = await esClient.search(ruleSearchOptions); + const body = await esClient.search(ruleSearchOptions); if (body.aggregations?.buckets?.buckets != null) { buckets = [...buckets, ...body.aggregations.buckets.buckets]; } diff --git a/x-pack/plugins/security_solution/server/usage/queries/utils/fetch_hits_with_pit.ts b/x-pack/plugins/security_solution/server/usage/queries/utils/fetch_hits_with_pit.ts index cc4d8d98df799..2d84cfe21179d 100644 --- a/x-pack/plugins/security_solution/server/usage/queries/utils/fetch_hits_with_pit.ts +++ b/x-pack/plugins/security_solution/server/usage/queries/utils/fetch_hits_with_pit.ts @@ -39,7 +39,7 @@ export const fetchHitsWithPit = async ({ index, keep_alive: '5m', }) - ).body.id; + ).id; let searchAfter: SortResults | undefined; let hits: Array> = []; @@ -56,7 +56,7 @@ export const fetchHitsWithPit = async ({ logger.debug( `Getting hits with point in time (PIT) query of: ${JSON.stringify(ruleSearchOptions)}` ); - const { body } = await esClient.search(ruleSearchOptions); + const body = await esClient.search(ruleSearchOptions); hits = [...hits, ...body.hits.hits]; searchAfter = body.hits.hits.length !== 0 ? body.hits.hits[body.hits.hits.length - 1].sort : undefined;