diff --git a/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts b/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts index 3ca60464d571b..501b6b8078da5 100644 --- a/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts +++ b/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts @@ -121,6 +121,35 @@ describe('Home page', () => { cy.url().should('include', '/app/metrics/detail/host/server1'); }); + it('Navigates to discover with default filter', () => { + cy.intercept('GET', '/internal/entities/managed/enablement', { + fixture: 'eem_enabled.json', + }).as('getEEMStatus'); + cy.visitKibana('/app/inventory'); + cy.wait('@getEEMStatus'); + cy.contains('Open in discover').click(); + cy.url().should( + 'include', + "query:(language:kuery,query:'entity.definition_id%20:%20builtin*" + ); + }); + + it('Navigates to discover with kuery filter', () => { + cy.intercept('GET', '/internal/entities/managed/enablement', { + fixture: 'eem_enabled.json', + }).as('getEEMStatus'); + cy.visitKibana('/app/inventory'); + cy.wait('@getEEMStatus'); + cy.getByTestSubj('queryInput').type('service.name : foo'); + + cy.contains('Update').click(); + cy.contains('Open in discover').click(); + cy.url().should( + 'include', + "query:'service.name%20:%20foo%20AND%20entity.definition_id%20:%20builtin*'" + ); + }); + it('Navigates to infra when clicking on a container type entity', () => { cy.intercept('GET', '/internal/entities/managed/enablement', { fixture: 'eem_enabled.json', diff --git a/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx b/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx index dee05d6f7cdd0..d5ed5b5af8cf9 100644 --- a/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx +++ b/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx @@ -17,7 +17,7 @@ import { ENTITY_LAST_SEEN, ENTITY_TYPE, } from '@kbn/observability-shared-plugin/common'; -import { ENTITIES_LATEST_ALIAS, EntityColumnIds } from '../../../common/entities'; +import { EntityColumnIds } from '../../../common/entities'; import { useInventoryParams } from '../../hooks/use_inventory_params'; import { useKibana } from '../../hooks/use_kibana'; @@ -38,17 +38,6 @@ export function DiscoverButton({ dataView }: { dataView: DataView }) { const filters: PhrasesFilter[] = []; - const entityDefinitionField = dataView.getFieldByName(ENTITY_DEFINITION_ID); - - if (entityDefinitionField) { - const entityDefinitionFilter = buildPhrasesFilter( - entityDefinitionField!, - [ENTITIES_LATEST_ALIAS], - dataView - ); - filters.push(entityDefinitionFilter); - } - const entityTypeField = dataView.getFieldByName(ENTITY_TYPE); if (entityTypes && entityTypeField) { @@ -56,10 +45,14 @@ export function DiscoverButton({ dataView }: { dataView: DataView }) { filters.push(entityTypeFilter); } + const kueryWithEntityDefinitionFilters = [kuery, `${ENTITY_DEFINITION_ID} : builtin*`] + .filter(Boolean) + .join(' AND '); + const discoverLink = discoverLocator?.getRedirectUrl({ indexPatternId: dataView?.id ?? '', columns: ACTIVE_COLUMNS, - query: { query: kuery ?? '', language: 'kuery' }, + query: { query: kueryWithEntityDefinitionFilters, language: 'kuery' }, filters, });