From e3cac218f011b3de0b39700feed1500f6129fd99 Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Thu, 29 Dec 2022 09:51:20 -0600 Subject: [PATCH] [data views] allow cross cluster index pattern negation (#147968) ## Summary The data views api examines comma delimited sections to see if there are matching indices before fetching the field list. The existing code checked for index pattern negation - patterns that started with a `-`. However, it didn't check for this in cross cluster case - `this_cluster:-kibana*`. The code now handles the cross cluster case appropriately. Still, its unclear to me whether this logic is necessary, hence why I opened https://github.com/elastic/kibana/pull/147970 - I was able to resolve the failed tests most familiar to me but I will need to work with engineers from other teams to investigate other failures. Closes https://github.com/elastic/kibana/issues/147926 --- .../data_views/server/fetcher/index_patterns_fetcher.test.ts | 4 ++-- .../data_views/server/fetcher/index_patterns_fetcher.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/data_views/server/fetcher/index_patterns_fetcher.test.ts b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.test.ts index b9925838fa9757..81a58c844fee47 100644 --- a/src/plugins/data_views/server/fetcher/index_patterns_fetcher.test.ts +++ b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.test.ts @@ -40,8 +40,8 @@ describe('Index Pattern Fetcher - server', () => { .mockResponseOnce(emptyResponse as unknown as estypes.FieldCapsResponse) .mockResponse(response as unknown as estypes.FieldCapsResponse); // first field caps request returns empty - const result = await indexPatterns.validatePatternListActive(['-a', 'b', 'c']); - expect(result).toEqual(['-a', 'c']); + const result = await indexPatterns.validatePatternListActive(['-a', 'b', 'c', 'a:-b']); + expect(result).toEqual(['-a', 'c', 'a:-b']); }); it('Returns all patterns when all match indices', async () => { esClient.fieldCaps.mockResponse(response as unknown as estypes.FieldCapsResponse); diff --git a/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts index 2d4b0d00c3ffda..df18a5d506f17f 100644 --- a/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts +++ b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts @@ -126,7 +126,7 @@ export class IndexPatternsFetcher { patternList .map(async (index) => { // perserve negated patterns - if (index.startsWith('-')) { + if (index.startsWith('-') || index.includes(':-')) { return true; } const searchResponse = await this.elasticsearchClient.fieldCaps({