[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

<img width="584" alt="image"
src="https://github.com/user-attachments/assets/05c3b244-3a0f-425a-82db-3498c1a6dbb7"
/>


### 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 <elasticmachine@users.noreply.github.com>
This commit is contained in:
Carlos Crespo 2025-03-04 16:46:21 +01:00 committed by GitHub
parent dfe542bd8e
commit 8e5b8580f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: {