From d8daf492dc67fa697ced40ff92e0fbdf88e59664 Mon Sep 17 00:00:00 2001 From: Wylie Conlon Date: Thu, 1 Oct 2020 12:57:45 -0400 Subject: [PATCH] Remove duplicate values --- .../lens/server/routes/existing_fields.test.ts | 18 +++--------------- .../lens/server/routes/existing_fields.ts | 10 ++-------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/lens/server/routes/existing_fields.test.ts b/x-pack/plugins/lens/server/routes/existing_fields.test.ts index 9941af03f0c19..c877e69d7b0dd 100644 --- a/x-pack/plugins/lens/server/routes/existing_fields.test.ts +++ b/x-pack/plugins/lens/server/routes/existing_fields.test.ts @@ -15,7 +15,6 @@ describe('existingFields', () => { name, isScript: false, isMeta: false, - path: name, ...obj, }; } @@ -51,28 +50,19 @@ describe('existingFields', () => { expect(result).toEqual(['geo.country_name']); }); - it('should use path, not name', () => { - const result = existingFields( - [searchResults({ 'stuff.foo': ['bar'] })], - [field({ name: 'goober', path: 'stuff.foo' })] - ); - - expect(result).toEqual(['goober']); - }); - it('supports scripted fields', () => { const result = existingFields( [searchResults({ bar: ['scriptvalue'] })], - [field({ name: 'baz', isScript: true, path: 'bar' })] + [field({ name: 'bar', isScript: true })] ); - expect(result).toEqual(['baz']); + expect(result).toEqual(['bar']); }); it('supports meta fields', () => { const result = existingFields( [{ _mymeta: 'abc', ...searchResults({ bar: ['scriptvalue'] }) }], - [field({ name: '_mymeta', isMeta: true, path: '_mymeta' })] + [field({ name: '_mymeta', isMeta: true })] ); expect(result).toEqual(['_mymeta']); @@ -103,7 +93,6 @@ describe('buildFieldList', () => { expect(fields.find((f) => f.isScript)).toMatchObject({ isScript: true, name: 'foo', - path: 'foo', lang: 'painless', script: '2+2', }); @@ -115,7 +104,6 @@ describe('buildFieldList', () => { isScript: false, isMeta: true, name: '_mymeta', - path: '_mymeta', }); }); }); diff --git a/x-pack/plugins/lens/server/routes/existing_fields.ts b/x-pack/plugins/lens/server/routes/existing_fields.ts index d9b31402f1ef1..c925517b572da 100644 --- a/x-pack/plugins/lens/server/routes/existing_fields.ts +++ b/x-pack/plugins/lens/server/routes/existing_fields.ts @@ -9,11 +9,7 @@ import { schema } from '@kbn/config-schema'; import { ILegacyScopedClusterClient, SavedObject, RequestHandlerContext } from 'src/core/server'; import { CoreSetup } from 'src/core/server'; import { BASE_API_URL } from '../../common'; -import { - IndexPatternsFetcher, - IndexPatternAttributes, - UI_SETTINGS, -} from '../../../../../src/plugins/data/server'; +import { IndexPatternAttributes, UI_SETTINGS } from '../../../../../src/plugins/data/server'; /** * The number of docs to sample to determine field empty status. @@ -24,7 +20,6 @@ export interface Field { name: string; isScript: boolean; isMeta: boolean; - path: string; lang?: string; script?: string; } @@ -139,7 +134,6 @@ export function buildFieldList( return { name: field.name, isScript: !!field.scripted, - path: field.name, lang: field.lang, script: field.script, // id is a special case - it doesn't show up in the meta field list, @@ -230,7 +224,7 @@ export function existingFields( if (field.isMeta) { fieldStore = doc; } - const value = fieldStore[field.path]; + const value = fieldStore[field.name]; if (Array.isArray(value) && value.length) { missingFields.delete(field); } else if (!Array.isArray(value) && value) {