diff --git a/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts b/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts index 99d62926eddd2..f89052b5427e4 100644 --- a/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts +++ b/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts @@ -24,8 +24,14 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< const orphanedJobsCountResponse = await client.asCurrentUser.count({ index: CONNECTORS_JOBS_INDEX, query: { - terms: { - 'connector.id': ids, + bool: { + must_not: [ + { + terms: { + 'connector.id': ids, + }, + }, + ], }, }, }); @@ -51,7 +57,7 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< }, { range: { - last_seen: { + started_at: { lt: moment().subtract(1, 'day').toISOString(), }, }, @@ -64,8 +70,21 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< const errorResponse = await client.asCurrentUser.count({ index: CONNECTORS_JOBS_INDEX, query: { - term: { - status: SyncStatus.ERROR, + bool: { + should: [ + { + term: { + status: SyncStatus.ERROR, + }, + }, + { + range: { + last_seen: { + lt: moment().subtract(30, 'minutes').toISOString(), + }, + }, + }, + ], }, }, }); @@ -109,7 +128,7 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< { range: { last_seen: { - gt: moment().subtract(30, 'minutes').toISOString(), + lt: moment().subtract(30, 'minutes').toISOString(), }, }, },