From 5dcd97557a5abd185982ef20f3c226c3c310fc7b Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Wed, 8 Jul 2020 17:10:06 -0700 Subject: [PATCH] Fixes filtering bug when user selects 'Environment: Not defined'. Now filters properly by filtering for docs where service.environment does not exist --- .../get_service_map_service_node_info.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts index 0f48fb5c07dd3..be92bfe5a0099 100644 --- a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts +++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts @@ -22,6 +22,7 @@ import { TRANSACTION_REQUEST, TRANSACTION_PAGE_LOAD, } from '../../../common/transaction_types'; +import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values'; interface Options { setup: Setup & SetupTimeRange; @@ -42,12 +43,23 @@ export async function getServiceMapServiceNodeInfo({ }: Options & { serviceName: string; environment?: string }) { const { start, end } = setup; + const environmentNotDefinedFilter = { + bool: { must_not: [{ exists: { field: SERVICE_ENVIRONMENT } }] }, + }; + const filter: ESFilter[] = [ { range: rangeFilter(start, end) }, { term: { [SERVICE_NAME]: serviceName } }, - ...(environment ? [{ term: { [SERVICE_ENVIRONMENT]: environment } }] : []), ]; + if (environment) { + filter.push( + environment === ENVIRONMENT_NOT_DEFINED + ? environmentNotDefinedFilter + : { term: { [SERVICE_ENVIRONMENT]: environment } } + ); + } + const minutes = Math.abs((end - start) / (1000 * 60)); const taskParams = {