From 8e5b8580f461b4f057ade98cf340e3a8bf8b9d6f Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Tue, 4 Mar 2025 16:46:21 +0100 Subject: [PATCH] [Infra] Fix hosts total count query (#212749) Fixes [#212745](https://github.com/elastic/kibana/issues/212745) ## Summary Fix for the hosts total count query, which was not correctly filtering hosts from system integration and APM image ### How to test - Connect Kibana to an edge cluster - Navigate to Infrastructure > Hosts - The total number of items on the table should be equal to the number in the hosts count KPI Co-authored-by: Elastic Machine --- .../routes/infra/lib/host/get_hosts_count.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/x-pack/solutions/observability/plugins/infra/server/routes/infra/lib/host/get_hosts_count.ts b/x-pack/solutions/observability/plugins/infra/server/routes/infra/lib/host/get_hosts_count.ts index 367c7a9309322..2440d045a01e4 100644 --- a/x-pack/solutions/observability/plugins/infra/server/routes/infra/lib/host/get_hosts_count.ts +++ b/x-pack/solutions/observability/plugins/infra/server/routes/infra/lib/host/get_hosts_count.ts @@ -25,8 +25,14 @@ export async function getHostsCount({ }) { assertQueryStructure(query); + const apmDocumentSources = await apmDataAccessServices?.getDocumentSources({ + start: from, + end: to, + }); + const documentsFilter = await getDocumentsFilter({ apmDataAccessServices, + apmDocumentSources, from, to, }); @@ -37,8 +43,15 @@ export async function getHostsCount({ track_total_hits: false, query: { bool: { - filter: [query, ...rangeQuery(from, to)], - should: [...documentsFilter], + filter: [ + query, + ...rangeQuery(from, to), + { + bool: { + should: [...documentsFilter], + }, + }, + ], }, }, aggs: {