From 7f7cfbcd4420f46576e884ac63a88e92fd0eee68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Tue, 30 Jul 2019 17:01:53 +0200 Subject: [PATCH] Conditionally add `should` params in transaction distribution ES query --- .../distribution/get_buckets/fetcher.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts index c33c4611b8bf59..8a155eec0b8304 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts @@ -37,6 +37,18 @@ export function bucketFetcher({ const { start, end, uiFiltersES, client, config } = setup; const bucketTargetCount = config.get('xpack.apm.bucketTargetCount'); + const should: Array> = [ + { term: { [TRANSACTION_SAMPLED]: true } } + ]; + + if (traceId) { + should.push({ term: { [TRACE_ID]: traceId } }); + } + + if (transactionId) { + should.push({ term: { [TRANSACTION_ID]: transactionId } }); + } + const params = { index: config.get('apm_oss.transactionIndices'), body: { @@ -51,11 +63,7 @@ export function bucketFetcher({ { range: rangeFilter(start, end) }, ...uiFiltersES ], - should: [ - { term: { [TRACE_ID]: traceId } }, // TODO: might fail when undefined - { term: { [TRANSACTION_ID]: transactionId } }, // TODO: might fail when undefined - { term: { [TRANSACTION_SAMPLED]: true } } - ] + should } }, aggs: {