From b9b3f5c0409fbcc351707b39cae3e69c1532c82e Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 16 Nov 2020 14:52:51 +0000 Subject: [PATCH 01/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20extract=20out?= =?UTF-8?q?=20createIndexPatternsService()=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns_service.ts | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/plugins/data/server/index_patterns/index_patterns_service.ts b/src/plugins/data/server/index_patterns/index_patterns_service.ts index af2d4d6a73e0f..7a40a8697a740 100644 --- a/src/plugins/data/server/index_patterns/index_patterns_service.ts +++ b/src/plugins/data/server/index_patterns/index_patterns_service.ts @@ -47,6 +47,10 @@ export interface IndexPatternsServiceStartDeps { } export class IndexPatternsService implements Plugin { + #uiSettings?: CoreStart['uiSettings']; + #fieldFormats?: FieldFormatsStart; + #logger?: Logger; + public setup(core: CoreSetup) { core.savedObjects.registerType(indexPatternSavedObjectType); core.capabilities.registerProvider(capabilitiesProvider); @@ -55,29 +59,37 @@ export class IndexPatternsService implements Plugin { - const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); - const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient); + indexPatternsServiceFactory: this.createIndexPatternsService.bind(this), + }; + } - return new IndexPatternsCommonService({ - uiSettings: new UiSettingsServerToCommon(uiSettingsClient), - savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient), - apiClient: new IndexPatternsApiServer(elasticsearchClient), - fieldFormats: formats, - onError: (error) => { - logger.error(error); - }, - onNotification: ({ title, text }) => { - logger.warn(`${title} : ${text}`); - }, - }); + public async createIndexPatternsService( + savedObjectsClient: SavedObjectsClientContract, + elasticsearchClient: ElasticsearchClient + ) { + if (!this.#uiSettings) throw new Error('UI Settings not set in IndexPatternsService.'); + if (!this.#fieldFormats) throw new Error('Field formats not set in IndexPatternsService.'); + if (!this.#logger) throw new Error('Logger not set in IndexPatternsService.'); + + const uiSettingsClient = this.#uiSettings.asScopedToClient(savedObjectsClient); + const formats = await this.#fieldFormats.fieldFormatServiceFactory(uiSettingsClient); + + return new IndexPatternsCommonService({ + uiSettings: new UiSettingsServerToCommon(uiSettingsClient), + savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient), + apiClient: new IndexPatternsApiServer(elasticsearchClient), + fieldFormats: formats, + onError: (error) => { + this.#logger!.error(error); }, - }; + onNotification: ({ title, text }) => { + this.#logger!.warn(`${title} : ${text}`); + }, + }); } } From 3a1c1c3ff050f9d908ed560346285425231de190 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 16 Nov 2020 14:53:19 +0000 Subject: [PATCH 02/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20create=20ind?= =?UTF-8?q?ex=20pattern=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/public/plugin.ts | 10 +++++ .../data/server/index_patterns/routes.ts | 4 ++ .../routes/create_index_pattern.ts | 39 +++++++++++++++++++ src/plugins/data/server/plugin.ts | 7 ++++ 4 files changed, 60 insertions(+) create mode 100644 src/plugins/data/server/index_patterns/routes/create_index_pattern.ts diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index afa8d935f367b..910835d0a7188 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -215,6 +215,16 @@ export class DataPublicPlugin trackUiMetric: this.usageCollection?.reportUiStats.bind(this.usageCollection, 'data_plugin'), }); + // core.http + // .fetch('/api/index_patterns/index_pattern', { + // method: 'POST', + // body: JSON.stringify({ + // name: 'test', + // }), + // }) + // .then((val) => console.log('val', val)) + // .catch((err) => console.log('err', err)); + return { ...dataServices, ui: { diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index f8af52954fc61..de6a1b4c5ae1c 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -20,6 +20,7 @@ import { schema } from '@kbn/config-schema'; import { HttpServiceSetup, RequestHandlerContext } from 'kibana/server'; import { IndexPatternsFetcher } from './fetcher'; +import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -33,6 +34,9 @@ export function registerRoutes(http: HttpServiceSetup) { }; const router = http.createRouter(); + + registerCreateIndexPatternRoute(router); + router.get( { path: '/api/index_patterns/_fields_for_wildcard', diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts new file mode 100644 index 0000000000000..31301780db028 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -0,0 +1,39 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from 'src/core/server'; + +export const registerCreateIndexPatternRoute = (router: IRouter) => { + router.post( + { + path: '/api/index_patterns/index_pattern', + validate: { + body: schema.object({ + name: schema.string(), + }), + }, + }, + router.handleLegacyErrors(async (ctx, req, res) => { + return res.ok({ + body: 'yuppppi!', + }); + }) + ); +}; diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 3ec4e7e64e382..0b33c526c94d4 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -93,6 +93,13 @@ export class DataServerPlugin this.autocompleteService.setup(core); this.kqlTelemetryService.setup(core, { usageCollection }); + // core.http.registerRouteHandlerContext( + // 'indexPatternsService', + // async (context, req, res): Promise<{}> => { + // return {}; + // } + // ); + core.uiSettings.register(getUiSettings()); const searchSetup = this.searchService.setup(core, { From d92eef5738764ead7483508ee911a70ebeade9d9 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 17 Nov 2020 13:33:17 +0000 Subject: [PATCH 03/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20index=20patt?= =?UTF-8?q?erns=20http=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/common/index_patterns/index.ts | 2 +- src/plugins/data/server/plugin.ts | 24 ++++++++++----- src/plugins/data/server/types.ts | 30 +++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/plugins/data/server/types.ts diff --git a/src/plugins/data/common/index_patterns/index.ts b/src/plugins/data/common/index_patterns/index.ts index 08f478404be2c..de0078df1b9e4 100644 --- a/src/plugins/data/common/index_patterns/index.ts +++ b/src/plugins/data/common/index_patterns/index.ts @@ -19,6 +19,6 @@ export * from './fields'; export * from './types'; -export { IndexPatternsService } from './index_patterns'; +export { IndexPatternsService, IndexPatternsContract } from './index_patterns'; export type { IndexPattern } from './index_patterns'; export * from './errors'; diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 0b33c526c94d4..597f461e0044e 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -30,6 +30,7 @@ import { UsageCollectionSetup } from '../../usage_collection/server'; import { AutocompleteService } from './autocomplete'; import { FieldFormatsService, FieldFormatsSetup, FieldFormatsStart } from './field_formats'; import { getUiSettings } from './ui_settings'; +import { IndexPatternsRequestHandlerContext } from './types'; export interface DataEnhancements { search: SearchEnhancements; @@ -87,18 +88,27 @@ export class DataServerPlugin core: CoreSetup, { expressions, usageCollection }: DataPluginSetupDependencies ) { - this.indexPatterns.setup(core); this.scriptsService.setup(core); this.queryService.setup(core); this.autocompleteService.setup(core); this.kqlTelemetryService.setup(core, { usageCollection }); - // core.http.registerRouteHandlerContext( - // 'indexPatternsService', - // async (context, req, res): Promise<{}> => { - // return {}; - // } - // ); + this.indexPatterns.setup(core); + core.http.registerRouteHandlerContext( + 'indexPatterns', + async (context, req, res): Promise => { + const savedObjectsClient = context.core.savedObjects.client; + const elasticsearchClient = context.core.elasticsearch.client.asCurrentUser; + const indexPatterns = await this.indexPatterns.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + + return { + indexPatterns, + }; + } + ); core.uiSettings.register(getUiSettings()); diff --git a/src/plugins/data/server/types.ts b/src/plugins/data/server/types.ts new file mode 100644 index 0000000000000..2e0d15353fef3 --- /dev/null +++ b/src/plugins/data/server/types.ts @@ -0,0 +1,30 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import type { IndexPatternsContract } from '../common'; + +export interface IndexPatternsRequestHandlerContext { + indexPatterns: IndexPatternsContract; +} + +declare module 'src/core/server' { + interface RequestHandlerContext { + indexPatterns?: IndexPatternsRequestHandlerContext; + } +} From 302e34b36a812511f84f8c3fdb4a936c2bb657a0 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 17 Nov 2020 18:22:08 +0100 Subject: [PATCH 04/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20schema=20for?= =?UTF-8?q?=20index=20pattern=20create=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/create_index_pattern.ts | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 31301780db028..fdaf9e3ea57de 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -20,17 +20,91 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from 'src/core/server'; +const serializedFieldFormatSchema = schema.object({ + id: schema.maybe(schema.string()), + params: schema.maybe(schema.any()), +}); + export const registerCreateIndexPatternRoute = (router: IRouter) => { router.post( { path: '/api/index_patterns/index_pattern', validate: { body: schema.object({ - name: schema.string(), + skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + make_default: schema.maybe(schema.boolean({ defaultValue: false })), + index_pattern: schema.object({ + id: schema.maybe(schema.string()), + version: schema.maybe(schema.string()), + title: schema.maybe(schema.string()), + type: schema.maybe(schema.string()), + intervalName: schema.maybe(schema.string()), + timeFieldName: schema.maybe(schema.string()), + sourceFilters: schema.maybe( + schema.arrayOf( + schema.object({ + value: schema.string(), + }) + ) + ), + fields: schema.maybe( + schema.recordOf( + schema.string(), + schema.object({ + name: schema.string(), + type: schema.string(), + searchable: schema.boolean(), + aggregatable: schema.boolean(), + count: schema.maybe(schema.number()), + script: schema.maybe(schema.string()), + lang: schema.maybe(schema.string()), + conflictDescriptions: schema.maybe( + schema.recordOf(schema.string(), schema.arrayOf(schema.string())) + ), + format: schema.maybe(serializedFieldFormatSchema), + esTypes: schema.maybe(schema.arrayOf(schema.string())), + scripted: schema.maybe(schema.boolean()), + readFromDocValues: schema.maybe(schema.boolean()), + subType: schema.maybe( + schema.object({ + multi: schema.maybe( + schema.object({ + parent: schema.string(), + }) + ), + nested: schema.maybe( + schema.object({ + path: schema.string(), + }) + ), + }) + ), + indexed: schema.maybe(schema.boolean()), + customName: schema.maybe(schema.string()), + shortDotsEnable: schema.maybe(schema.boolean()), + }) + ) + ), + typeMeta: schema.maybe(schema.object({}, { unknowns: 'allow' })), + fieldFormats: schema.maybe( + schema.recordOf(schema.string(), serializedFieldFormatSchema) + ), + fieldAttrs: schema.maybe( + schema.recordOf( + schema.string(), + schema.object({ + customName: schema.string(), + }) + ) + ), + }), }), }, }, router.handleLegacyErrors(async (ctx, req, res) => { + // if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); + // const ip = ctx.indexPatterns.indexPatterns; + return res.ok({ body: 'yuppppi!', }); From c5d11db8b35b1b68baccb9243fa4336228422007 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 17 Nov 2020 19:45:11 +0100 Subject: [PATCH 05/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20compose=20sche?= =?UTF-8?q?ma=20out=20of=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/create_index_pattern.ts | 127 +++++++++--------- 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index fdaf9e3ea57de..f3a1470c367f9 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -25,6 +25,67 @@ const serializedFieldFormatSchema = schema.object({ params: schema.maybe(schema.any()), }); +const fieldSpecSchema = schema.object({ + name: schema.string(), + type: schema.string(), + searchable: schema.boolean(), + aggregatable: schema.boolean(), + count: schema.maybe(schema.number()), + script: schema.maybe(schema.string()), + lang: schema.maybe(schema.string()), + conflictDescriptions: schema.maybe( + schema.recordOf(schema.string(), schema.arrayOf(schema.string())) + ), + format: schema.maybe(serializedFieldFormatSchema), + esTypes: schema.maybe(schema.arrayOf(schema.string())), + scripted: schema.maybe(schema.boolean()), + readFromDocValues: schema.maybe(schema.boolean()), + subType: schema.maybe( + schema.object({ + multi: schema.maybe( + schema.object({ + parent: schema.string(), + }) + ), + nested: schema.maybe( + schema.object({ + path: schema.string(), + }) + ), + }) + ), + indexed: schema.maybe(schema.boolean()), + customName: schema.maybe(schema.string()), + shortDotsEnable: schema.maybe(schema.boolean()), +}); + +const indexPatternSpecSchema = schema.object({ + id: schema.maybe(schema.string()), + version: schema.maybe(schema.string()), + title: schema.maybe(schema.string()), + type: schema.maybe(schema.string()), + intervalName: schema.maybe(schema.string()), + timeFieldName: schema.maybe(schema.string()), + sourceFilters: schema.maybe( + schema.arrayOf( + schema.object({ + value: schema.string(), + }) + ) + ), + fields: schema.maybe(schema.recordOf(schema.string(), fieldSpecSchema)), + typeMeta: schema.maybe(schema.object({}, { unknowns: 'allow' })), + fieldFormats: schema.maybe(schema.recordOf(schema.string(), serializedFieldFormatSchema)), + fieldAttrs: schema.maybe( + schema.recordOf( + schema.string(), + schema.object({ + customName: schema.string(), + }) + ) + ), +}); + export const registerCreateIndexPatternRoute = (router: IRouter) => { router.post( { @@ -33,71 +94,7 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { body: schema.object({ skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), make_default: schema.maybe(schema.boolean({ defaultValue: false })), - index_pattern: schema.object({ - id: schema.maybe(schema.string()), - version: schema.maybe(schema.string()), - title: schema.maybe(schema.string()), - type: schema.maybe(schema.string()), - intervalName: schema.maybe(schema.string()), - timeFieldName: schema.maybe(schema.string()), - sourceFilters: schema.maybe( - schema.arrayOf( - schema.object({ - value: schema.string(), - }) - ) - ), - fields: schema.maybe( - schema.recordOf( - schema.string(), - schema.object({ - name: schema.string(), - type: schema.string(), - searchable: schema.boolean(), - aggregatable: schema.boolean(), - count: schema.maybe(schema.number()), - script: schema.maybe(schema.string()), - lang: schema.maybe(schema.string()), - conflictDescriptions: schema.maybe( - schema.recordOf(schema.string(), schema.arrayOf(schema.string())) - ), - format: schema.maybe(serializedFieldFormatSchema), - esTypes: schema.maybe(schema.arrayOf(schema.string())), - scripted: schema.maybe(schema.boolean()), - readFromDocValues: schema.maybe(schema.boolean()), - subType: schema.maybe( - schema.object({ - multi: schema.maybe( - schema.object({ - parent: schema.string(), - }) - ), - nested: schema.maybe( - schema.object({ - path: schema.string(), - }) - ), - }) - ), - indexed: schema.maybe(schema.boolean()), - customName: schema.maybe(schema.string()), - shortDotsEnable: schema.maybe(schema.boolean()), - }) - ) - ), - typeMeta: schema.maybe(schema.object({}, { unknowns: 'allow' })), - fieldFormats: schema.maybe( - schema.recordOf(schema.string(), serializedFieldFormatSchema) - ), - fieldAttrs: schema.maybe( - schema.recordOf( - schema.string(), - schema.object({ - customName: schema.string(), - }) - ) - ), - }), + index_pattern: indexPatternSpecSchema, }), }, }, From 75fc9b78d785425cc483dd1e416b5134aeda97b6 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 17 Nov 2020 19:55:52 +0100 Subject: [PATCH 06/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20allow=20to=20not?= =?UTF-8?q?=20make=20the=20new=20index=20pattern=20a=20default=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns.test.ts | 25 +++++++++++++------ .../index_patterns/index_patterns.ts | 23 +++++++++++++---- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts index b22437ebbdb4e..1f9b01bc65613 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts @@ -183,13 +183,24 @@ describe('IndexPatterns', () => { expect(indexPatterns.refreshFields).toBeCalled(); }); - test('createAndSave', async () => { - const title = 'kibana-*'; - indexPatterns.createSavedObject = jest.fn(); - indexPatterns.setDefault = jest.fn(); - await indexPatterns.createAndSave({ title }); - expect(indexPatterns.createSavedObject).toBeCalled(); - expect(indexPatterns.setDefault).toBeCalled(); + describe('createAndSave', () => { + test('creates "index pattern" saved object and and makes it the default index pattern', async () => { + const title = 'kibana-*'; + indexPatterns.createSavedObject = jest.fn(); + indexPatterns.setDefault = jest.fn(); + await indexPatterns.createAndSave({ title }); + expect(indexPatterns.createSavedObject).toBeCalled(); + expect(indexPatterns.setDefault).toBeCalled(); + }); + + test('when `makeDefault` is false, does not make the new index pattern the default index pattern', async () => { + const title = 'kibana-*'; + indexPatterns.createSavedObject = jest.fn(); + indexPatterns.setDefault = jest.fn(); + await indexPatterns.createAndSave({ title }, false, false, false); + expect(indexPatterns.createSavedObject).toBeCalled(); + expect(indexPatterns.setDefault).not.toBeCalled(); + }); }); test('savedObjectToSpec', () => { diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 4f91079c1e139..cc4428bf90927 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -468,16 +468,29 @@ export class IndexPatternsService { } /** - * Create a new index pattern and save it right away + * Create a new index pattern and save it right away and make the default + * index pattern. + * * @param spec - * @param override Overwrite if existing index pattern exists - * @param skipFetchFields + * @param override Overwrite if existing index pattern exists. + * @param skipFetchFields Whether to skip field refresh step. + * @param makeDefault Whether to make the new index pattern the default + * index pattern. */ - async createAndSave(spec: IndexPatternSpec, override = false, skipFetchFields = false) { + async createAndSave( + spec: IndexPatternSpec, + override = false, + skipFetchFields = false, + makeDefault: boolean = true + ) { const indexPattern = await this.create(spec, skipFetchFields); await this.createSavedObject(indexPattern, override); - await this.setDefault(indexPattern.id as string); + + if (makeDefault) { + await this.setDefault(indexPattern.id!); + } + return indexPattern; } From 60a1f87d852840861fefa064d6f7f50993fe859d Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 17 Nov 2020 20:12:55 +0100 Subject: [PATCH 07/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20implement=20index?= =?UTF-8?q?=20pattern=20create=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/create_index_pattern.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index f3a1470c367f9..683ab11662e18 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -92,18 +92,29 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { path: '/api/index_patterns/index_pattern', validate: { body: schema.object({ + override: schema.maybe(schema.boolean({ defaultValue: false })), skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), - make_default: schema.maybe(schema.boolean({ defaultValue: false })), + make_default: schema.maybe(schema.boolean({ defaultValue: true })), index_pattern: indexPatternSpecSchema, }), }, }, router.handleLegacyErrors(async (ctx, req, res) => { - // if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); - // const ip = ctx.indexPatterns.indexPatterns; + if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); + + const ip = ctx.indexPatterns.indexPatterns; + const body = req.body; + const indexPattern = await ip.createAndSave( + body.index_pattern, + body.override || false, + body.skip_field_refresh || false, + body.make_default || true + ); return res.ok({ - body: 'yuppppi!', + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), }); }) ); From f5f51bfd939a07c2c08f0692554c9b0936984ec0 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 17 Nov 2020 20:16:21 +0100 Subject: [PATCH 08/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20add=20index?= =?UTF-8?q?=20pattern=20create=20endpoint=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index 33c07078c5348..b509f3514398e 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -48,6 +48,76 @@ Coming soon. Coming soon. +### Index Patterns HTTP API + +Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: + +- `POST /api/index_patterns/index_pattern` — create an index pattern + +#### Create an index pattern + +Create an index pattern with a custom title. + +``` +POST /api/index_patterns/index_pattern +{ + "index_pattern": { + "title": "hello" + } +} +``` + +Customize creation behavior with: + +- `override` --- if set to `true`, replaces an existing index pattern if an + index pattern with the provided title already exists. Defaults to `false`. +- `skip_field_refresh` --- if set to `true` skips reloading index pattern fields after + the index pattern is stored. Defaults to `false`. +- `make_default` --- if set to `true`, makes the new index pattern the default + index pattern. Defaults to `true`. + +``` +POST /api/index_patterns/index_pattern +{ + "override": false, + "skip_field_refresh": false, + "make_default": true, + "index_pattern": { + "title": "hello" + } +} +``` + +At creation all index pattern fields are option and you can provide them. + +``` +POST /api/index_patterns/index_pattern +{ + "index_pattern": { + "id": "...", + "version": "...", + "title": "...", + "type": "...", + "intervalName": "...", + "timeFieldName": "...", + "sourceFilters": [], + "fields": {}, + "typeMeta": {}, + "fieldFormats": {}, + "fieldAttrs": {} + } +} +``` + +The endpoint returns the created index pattern object. + +```json +{ + "index_pattern": {} +} +``` + + ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. From c66eb9601b2c7349e34e22a7148988047c63b45e Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 18 Nov 2020 17:29:07 +0100 Subject: [PATCH 09/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20error=20handl?= =?UTF-8?q?ing=20wrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns.ts | 4 +- .../routes/create_index_pattern.ts | 35 ++++++------ .../routes/util/handle_errors.ts | 53 +++++++++++++++++++ 3 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/util/handle_errors.ts diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index cc4428bf90927..210b247fba782 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -219,7 +219,7 @@ export class IndexPatternsService { */ getFieldsForWildcard = async (options: GetFieldsOptions) => { const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS); - return this.apiClient.getFieldsForWildcard({ + return await this.apiClient.getFieldsForWildcard({ pattern: options.pattern, metaFields, type: options.type, @@ -235,7 +235,7 @@ export class IndexPatternsService { indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions ) => - this.getFieldsForWildcard({ + await this.getFieldsForWildcard({ type: indexPattern.type, rollupIndex: indexPattern?.typeMeta?.params?.rollup_index, ...options, diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 683ab11662e18..471f470fe3737 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -19,6 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from 'src/core/server'; +import { handleErrors } from './util/handle_errors'; const serializedFieldFormatSchema = schema.object({ id: schema.maybe(schema.string()), @@ -99,23 +100,25 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { }), }, }, - router.handleLegacyErrors(async (ctx, req, res) => { - if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); + router.handleLegacyErrors( + handleErrors(async (ctx, req, res) => { + if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); - const ip = ctx.indexPatterns.indexPatterns; - const body = req.body; - const indexPattern = await ip.createAndSave( - body.index_pattern, - body.override || false, - body.skip_field_refresh || false, - body.make_default || true - ); + const ip = ctx.indexPatterns.indexPatterns; + const body = req.body; + const indexPattern = await ip.createAndSave( + body.index_pattern, + body.override || false, + body.skip_field_refresh || false, + body.make_default || true + ); - return res.ok({ - body: JSON.stringify({ - index_pattern: indexPattern.toSpec(), - }), - }); - }) + return res.ok({ + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts new file mode 100644 index 0000000000000..f7ffe1ffcb704 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { RequestHandler, RouteMethod } from 'src/core/server'; + +interface ErrorResponseBody { + message: string; + attributes?: object; +} + +interface ErrorWithData { + data?: object; +} + +export const handleErrors = ( + handler: RequestHandler +): RequestHandler => async (context, request, response) => { + try { + return await handler(context, request, response); + } catch (error) { + if (error instanceof Error) { + const body: ErrorResponseBody = { + message: error.message, + }; + + if (typeof (error as ErrorWithData).data === 'object') { + body.attributes = (error as ErrorWithData).data; + } + + return response.badRequest({ + body, + }); + } + + throw error; + } +}; From 0f0b4d6cafd2a549863cc7849e0248130dd266cf Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 18 Nov 2020 18:07:30 +0100 Subject: [PATCH 10/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20index=20patt?= =?UTF-8?q?ern=20GET=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes.ts | 2 + .../routes/create_index_pattern.ts | 2 +- .../routes/get_index_pattern.ts | 56 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/plugins/data/server/index_patterns/routes/get_index_pattern.ts diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index de6a1b4c5ae1c..8c1a9700d7e34 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -21,6 +21,7 @@ import { schema } from '@kbn/config-schema'; import { HttpServiceSetup, RequestHandlerContext } from 'kibana/server'; import { IndexPatternsFetcher } from './fetcher'; import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; +import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -36,6 +37,7 @@ export function registerRoutes(http: HttpServiceSetup) { const router = http.createRouter(); registerCreateIndexPatternRoute(router); + registerGetIndexPatternRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 471f470fe3737..c15d22054c26b 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -18,7 +18,7 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from 'src/core/server'; +import { IRouter } from '../../../../../core/server'; import { handleErrors } from './util/handle_errors'; const serializedFieldFormatSchema = schema.object({ diff --git a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts new file mode 100644 index 0000000000000..9be6312079012 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts @@ -0,0 +1,56 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../core/server'; +import { handleErrors } from './util/handle_errors'; + +export const registerGetIndexPatternRoute = (router: IRouter) => { + router.get( + { + path: '/api/index_patterns/index_pattern/{id}', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + }, + }, + router.handleLegacyErrors( + handleErrors(async (ctx, req, res) => { + if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); + + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const indexPattern = await ip.get(id); + + return res.ok({ + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) + ); +}; From d13c1468916d540d8e21bb7246a576a9b56e0b12 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 18 Nov 2020 18:10:57 +0100 Subject: [PATCH 11/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20add=20index?= =?UTF-8?q?=20pattern=20GET=20mention=20to=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index b509f3514398e..1e8a1d0278e5b 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -53,6 +53,7 @@ Coming soon. Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - `POST /api/index_patterns/index_pattern` — create an index pattern +- `GET /api/index_patterns/index_pattern/{id}` — fetch an index pattern by `{id}` #### Create an index pattern @@ -118,6 +119,35 @@ The endpoint returns the created index pattern object. ``` +### Fetch an index pattern by ID + +Retrieve and index pattern by its ID. + +``` +GET /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +``` + +Returns an index pattern object. + +```json +{ + "index_pattern": { + "id": "...", + "version": "...", + "title": "...", + "type": "...", + "intervalName": "...", + "timeFieldName": "...", + "sourceFilters": [], + "fields": {}, + "typeMeta": {}, + "fieldFormats": {}, + "fieldAttrs": {} + } +} +``` + + ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. From 6d54f2e38cc5de5e75b14ee92dda77fc42c85790 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 18 Nov 2020 18:22:46 +0100 Subject: [PATCH 12/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20higher=20ord?= =?UTF-8?q?er=20route=20handler=20to=20check=20for=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/create_index_pattern.ts | 35 +++++++++--------- .../routes/get_index_pattern.ts | 25 ++++++------- .../util/assert_index_patterns_context.ts | 36 +++++++++++++++++++ .../routes/util/handle_errors.ts | 11 ++++++ src/plugins/data/server/types.ts | 22 ++++++++++++ 5 files changed, 100 insertions(+), 29 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index c15d22054c26b..736251b0a203e 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -19,6 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; +import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; const serializedFieldFormatSchema = schema.object({ @@ -101,24 +102,24 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { }, }, router.handleLegacyErrors( - handleErrors(async (ctx, req, res) => { - if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const body = req.body; + const indexPattern = await ip.createAndSave( + body.index_pattern, + body.override || false, + body.skip_field_refresh || false, + body.make_default || true + ); - const ip = ctx.indexPatterns.indexPatterns; - const body = req.body; - const indexPattern = await ip.createAndSave( - body.index_pattern, - body.override || false, - body.skip_field_refresh || false, - body.make_default || true - ); - - return res.ok({ - body: JSON.stringify({ - index_pattern: indexPattern.toSpec(), - }), - }); - }) + return res.ok({ + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts index 9be6312079012..bea08ab641895 100644 --- a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts @@ -19,6 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; +import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; export const registerGetIndexPatternRoute = (router: IRouter) => { @@ -38,19 +39,19 @@ export const registerGetIndexPatternRoute = (router: IRouter) => { }, }, router.handleLegacyErrors( - handleErrors(async (ctx, req, res) => { - if (!ctx.indexPatterns) throw new Error('Index pattern context is missing.'); + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const indexPattern = await ip.get(id); - const ip = ctx.indexPatterns.indexPatterns; - const id = req.params.id; - const indexPattern = await ip.get(id); - - return res.ok({ - body: JSON.stringify({ - index_pattern: indexPattern.toSpec(), - }), - }); - }) + return res.ok({ + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts b/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts new file mode 100644 index 0000000000000..b6c7e1fb1a443 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts @@ -0,0 +1,36 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { RequestHandler, RequestHandlerContext, RouteMethod } from '../../../../../../core/server'; +import { IndexPatternsRouteContext, IndexPatternsRequestHandler } from '../../../types'; + +const isTagsRouteContext = (context: RequestHandlerContext): context is IndexPatternsRouteContext => + !!context.indexPatterns; + +/** + * This higher order request handler makes sure that `ctx.indexPatterns` + * property is present. + */ +export const assertIndexPatternsContext = ( + handler: IndexPatternsRequestHandler +): RequestHandler => (context, request, response) => { + return isTagsRouteContext(context) + ? handler(context, request, response) + : response.badRequest({ body: 'IndexPatternsRequestHandlerContext is not registered.' }); +}; diff --git a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts index f7ffe1ffcb704..80ee13614977c 100644 --- a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts +++ b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts @@ -28,6 +28,17 @@ interface ErrorWithData { data?: object; } +/** + * This higher order request handler makes sure that errors are returned with + * body formatted in the following shape: + * + * ```json + * { + * "message": "...", + * "attributes": {} + * } + * ``` + */ export const handleErrors = ( handler: RequestHandler ): RequestHandler => async (context, request, response) => { diff --git a/src/plugins/data/server/types.ts b/src/plugins/data/server/types.ts index 2e0d15353fef3..ee8e9d28b3f05 100644 --- a/src/plugins/data/server/types.ts +++ b/src/plugins/data/server/types.ts @@ -17,6 +17,13 @@ * under the License. */ +import { + IKibanaResponse, + KibanaRequest, + KibanaResponseFactory, + RequestHandlerContext, + RouteMethod, +} from 'src/core/server'; import type { IndexPatternsContract } from '../common'; export interface IndexPatternsRequestHandlerContext { @@ -28,3 +35,18 @@ declare module 'src/core/server' { indexPatterns?: IndexPatternsRequestHandlerContext; } } + +export type IndexPatternsRouteContext = RequestHandlerContext & + Required>; + +export type IndexPatternsRequestHandler< + P = unknown, + Q = unknown, + B = unknown, + Method extends RouteMethod = any, + ResponseFactory extends KibanaResponseFactory = KibanaResponseFactory +> = ( + context: IndexPatternsRouteContext, + request: KibanaRequest, + response: ResponseFactory +) => IKibanaResponse | Promise>; From feacd9eadd00155b1090bb0eca9cfa0e00e933e7 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 18 Nov 2020 18:24:55 +0100 Subject: [PATCH 13/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20index=20patt?= =?UTF-8?q?ern=20deletion=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes.ts | 2 + .../routes/delete_index_pattern.ts | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 8c1a9700d7e34..d049ef1fd2d8c 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -22,6 +22,7 @@ import { HttpServiceSetup, RequestHandlerContext } from 'kibana/server'; import { IndexPatternsFetcher } from './fetcher'; import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; +import { registerDeleteIndexPatternRoute } from './routes/delete_index_pattern'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -38,6 +39,7 @@ export function registerRoutes(http: HttpServiceSetup) { registerCreateIndexPatternRoute(router); registerGetIndexPatternRoute(router); + registerDeleteIndexPatternRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts new file mode 100644 index 0000000000000..f7510d9b00b7b --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts @@ -0,0 +1,54 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../core/server'; +import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; +import { handleErrors } from './util/handle_errors'; + +export const registerDeleteIndexPatternRoute = (router: IRouter) => { + router.delete( + { + path: '/api/index_patterns/index_pattern/{id}', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + + await ip.delete(id); + + return res.ok(); + }) + ) + ) + ); +}; From 1530e9415a7d8cedc61e89d1af19885bae4bbb26 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 18 Nov 2020 18:26:45 +0100 Subject: [PATCH 14/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20add=20delete?= =?UTF-8?q?=20endpoint=20docs=20entry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index 1e8a1d0278e5b..3554f8310baa4 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -54,6 +54,7 @@ Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - `POST /api/index_patterns/index_pattern` — create an index pattern - `GET /api/index_patterns/index_pattern/{id}` — fetch an index pattern by `{id}` +- `DELETE /api/index_patterns/index_pattern/{id}` — delete an index pattern by `{id}` #### Create an index pattern @@ -148,6 +149,17 @@ Returns an index pattern object. ``` +### Delete an index pattern by ID + +Delete and index pattern by its ID. + +``` +DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +``` + +Returns an '200 OK` response with empty body on success. + + ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. From 512887296315ecc2ea1a9936a8e8e9e23cae180d Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 14:04:21 +0000 Subject: [PATCH 15/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20index=20patt?= =?UTF-8?q?ern=20update=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes.ts | 2 + .../routes/update_index_pattern.ts | 86 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/plugins/data/server/index_patterns/routes/update_index_pattern.ts diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index d049ef1fd2d8c..333595b05ce99 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -23,6 +23,7 @@ import { IndexPatternsFetcher } from './fetcher'; import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; import { registerDeleteIndexPatternRoute } from './routes/delete_index_pattern'; +import { registerUpdateIndexPatternRoute } from './routes/update_index_pattern'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -40,6 +41,7 @@ export function registerRoutes(http: HttpServiceSetup) { registerCreateIndexPatternRoute(router); registerGetIndexPatternRoute(router); registerDeleteIndexPatternRoute(router); + registerUpdateIndexPatternRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts new file mode 100644 index 0000000000000..23cf6d39c8a9f --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -0,0 +1,86 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../core/server'; +import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; +import { handleErrors } from './util/handle_errors'; + +const indexPatternUpdateSchema = schema.object({ + title: schema.maybe(schema.string()), +}); + +export const registerUpdateIndexPatternRoute = (router: IRouter) => { + router.post( + { + path: '/api/index_patterns/index_pattern/{id}', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + body: schema.object({ + index_pattern: indexPatternUpdateSchema, + }), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + + const indexPattern = await ip.get(id); + + const { + index_pattern: { title }, + } = req.body; + + let changeCount = 0; + + if (title !== undefined && title !== indexPattern.title) { + changeCount++; + indexPattern.title = title; + } + + if (!changeCount) { + return res.badRequest({ + body: JSON.stringify({ + message: 'Index pattern chagne set is empty.', + }), + }); + } + + await ip.updateSavedObject(indexPattern); + + return res.ok({ + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) + ) + ); +}; From 9dfbc35672efe45f501822ef013e6de408a01bcc Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 14:06:35 +0000 Subject: [PATCH 16/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20ability=20to?= =?UTF-8?q?=20update=20timeFieldName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/routes/update_index_pattern.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 23cf6d39c8a9f..4a54549524e3f 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -24,6 +24,7 @@ import { handleErrors } from './util/handle_errors'; const indexPatternUpdateSchema = schema.object({ title: schema.maybe(schema.string()), + timeFieldName: schema.maybe(schema.string()), }); export const registerUpdateIndexPatternRoute = (router: IRouter) => { @@ -54,7 +55,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { const indexPattern = await ip.get(id); const { - index_pattern: { title }, + index_pattern: { title, timeFieldName }, } = req.body; let changeCount = 0; @@ -64,7 +65,12 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { indexPattern.title = title; } - if (!changeCount) { + if (timeFieldName !== undefined && timeFieldName !== indexPattern.timeFieldName) { + changeCount++; + indexPattern.timeFieldName = timeFieldName; + } + + if (changeCount < 1) { return res.badRequest({ body: JSON.stringify({ message: 'Index pattern chagne set is empty.', From 6a2af503176eda5bd78237a5ae4ee094f9ce433d Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 14:27:01 +0000 Subject: [PATCH 17/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20ability=20to?= =?UTF-8?q?=20edit=20intervalName,=20sourceFilters,=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/create_index_pattern.ts | 40 +------------ .../routes/update_index_pattern.ts | 27 ++++++++- .../index_patterns/routes/util/schemas.ts | 59 +++++++++++++++++++ 3 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/util/schemas.ts diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 736251b0a203e..ca16aac983d68 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -21,45 +21,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; - -const serializedFieldFormatSchema = schema.object({ - id: schema.maybe(schema.string()), - params: schema.maybe(schema.any()), -}); - -const fieldSpecSchema = schema.object({ - name: schema.string(), - type: schema.string(), - searchable: schema.boolean(), - aggregatable: schema.boolean(), - count: schema.maybe(schema.number()), - script: schema.maybe(schema.string()), - lang: schema.maybe(schema.string()), - conflictDescriptions: schema.maybe( - schema.recordOf(schema.string(), schema.arrayOf(schema.string())) - ), - format: schema.maybe(serializedFieldFormatSchema), - esTypes: schema.maybe(schema.arrayOf(schema.string())), - scripted: schema.maybe(schema.boolean()), - readFromDocValues: schema.maybe(schema.boolean()), - subType: schema.maybe( - schema.object({ - multi: schema.maybe( - schema.object({ - parent: schema.string(), - }) - ), - nested: schema.maybe( - schema.object({ - path: schema.string(), - }) - ), - }) - ), - indexed: schema.maybe(schema.boolean()), - customName: schema.maybe(schema.string()), - shortDotsEnable: schema.maybe(schema.boolean()), -}); +import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; const indexPatternSpecSchema = schema.object({ id: schema.maybe(schema.string()), diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 4a54549524e3f..68f82588245ce 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -21,10 +21,20 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; +import { serializedFieldFormatSchema } from './util/schemas'; const indexPatternUpdateSchema = schema.object({ title: schema.maybe(schema.string()), timeFieldName: schema.maybe(schema.string()), + intervalName: schema.maybe(schema.string()), + sourceFilters: schema.maybe( + schema.arrayOf( + schema.object({ + value: schema.string(), + }) + ) + ), + fieldFormats: schema.maybe(schema.recordOf(schema.string(), serializedFieldFormatSchema)), }); export const registerUpdateIndexPatternRoute = (router: IRouter) => { @@ -55,7 +65,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { const indexPattern = await ip.get(id); const { - index_pattern: { title, timeFieldName }, + index_pattern: { title, timeFieldName, intervalName, sourceFilters, fieldFormats }, } = req.body; let changeCount = 0; @@ -70,6 +80,21 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { indexPattern.timeFieldName = timeFieldName; } + if (intervalName !== undefined && intervalName !== indexPattern.intervalName) { + changeCount++; + indexPattern.intervalName = intervalName; + } + + if (sourceFilters !== undefined) { + changeCount++; + indexPattern.sourceFilters = sourceFilters; + } + + if (fieldFormats !== undefined) { + changeCount++; + indexPattern.fieldFormatMap = fieldFormats; + } + if (changeCount < 1) { return res.badRequest({ body: JSON.stringify({ diff --git a/src/plugins/data/server/index_patterns/routes/util/schemas.ts b/src/plugins/data/server/index_patterns/routes/util/schemas.ts new file mode 100644 index 0000000000000..5e7dc985ea5c6 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/util/schemas.ts @@ -0,0 +1,59 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; + +export const serializedFieldFormatSchema = schema.object({ + id: schema.maybe(schema.string()), + params: schema.maybe(schema.any()), +}); + +export const fieldSpecSchema = schema.object({ + name: schema.string(), + type: schema.string(), + searchable: schema.boolean(), + aggregatable: schema.boolean(), + count: schema.maybe(schema.number()), + script: schema.maybe(schema.string()), + lang: schema.maybe(schema.string()), + conflictDescriptions: schema.maybe( + schema.recordOf(schema.string(), schema.arrayOf(schema.string())) + ), + format: schema.maybe(serializedFieldFormatSchema), + esTypes: schema.maybe(schema.arrayOf(schema.string())), + scripted: schema.maybe(schema.boolean()), + readFromDocValues: schema.maybe(schema.boolean()), + subType: schema.maybe( + schema.object({ + multi: schema.maybe( + schema.object({ + parent: schema.string(), + }) + ), + nested: schema.maybe( + schema.object({ + path: schema.string(), + }) + ), + }) + ), + indexed: schema.maybe(schema.boolean()), + customName: schema.maybe(schema.string()), + shortDotsEnable: schema.maybe(schema.boolean()), +}); From 0b013dd3b056c6e99cf2907535a3e34edcd5d979 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 14:40:44 +0000 Subject: [PATCH 18/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20allow=20updating?= =?UTF-8?q?=20index=20pattern=20type=20and=20typeMeta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/update_index_pattern.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 68f82588245ce..9952c1528a57e 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -25,6 +25,8 @@ import { serializedFieldFormatSchema } from './util/schemas'; const indexPatternUpdateSchema = schema.object({ title: schema.maybe(schema.string()), + type: schema.maybe(schema.string()), + typeMeta: schema.maybe(schema.object({}, { unknowns: 'allow' })), timeFieldName: schema.maybe(schema.string()), intervalName: schema.maybe(schema.string()), sourceFilters: schema.maybe( @@ -65,7 +67,15 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { const indexPattern = await ip.get(id); const { - index_pattern: { title, timeFieldName, intervalName, sourceFilters, fieldFormats }, + index_pattern: { + title, + timeFieldName, + intervalName, + sourceFilters, + fieldFormats, + type, + typeMeta, + }, } = req.body; let changeCount = 0; @@ -95,6 +105,16 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { indexPattern.fieldFormatMap = fieldFormats; } + if (type !== undefined) { + changeCount++; + indexPattern.type = type; + } + + if (typeMeta !== undefined) { + changeCount++; + indexPattern.typeMeta = typeMeta; + } + if (changeCount < 1) { return res.badRequest({ body: JSON.stringify({ From b6bb3aedbb1721a8eb9bbe87943a6e089a8f99ac Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 14:53:40 +0000 Subject: [PATCH 19/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20ability=20to?= =?UTF-8?q?=20update=20index=5Fpattern=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/update_index_pattern.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 9952c1528a57e..1aaac1b50df05 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -21,7 +21,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; -import { serializedFieldFormatSchema } from './util/schemas'; +import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; const indexPatternUpdateSchema = schema.object({ title: schema.maybe(schema.string()), @@ -37,6 +37,7 @@ const indexPatternUpdateSchema = schema.object({ ) ), fieldFormats: schema.maybe(schema.recordOf(schema.string(), serializedFieldFormatSchema)), + fields: schema.maybe(schema.recordOf(schema.string(), fieldSpecSchema)), }); export const registerUpdateIndexPatternRoute = (router: IRouter) => { @@ -54,6 +55,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ + skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), index_pattern: indexPatternUpdateSchema, }), }, @@ -67,6 +69,8 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { const indexPattern = await ip.get(id); const { + // eslint-disable-next-line @typescript-eslint/naming-convention + skip_field_refresh = false, index_pattern: { title, timeFieldName, @@ -75,10 +79,12 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { fieldFormats, type, typeMeta, + fields, }, } = req.body; let changeCount = 0; + let doRefreshFields = false; if (title !== undefined && title !== indexPattern.title) { changeCount++; @@ -115,6 +121,12 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { indexPattern.typeMeta = typeMeta; } + if (fields !== undefined) { + changeCount++; + doRefreshFields = true; + indexPattern.fields.replaceAll(Object.values(fields || {})); + } + if (changeCount < 1) { return res.badRequest({ body: JSON.stringify({ @@ -125,6 +137,10 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { await ip.updateSavedObject(indexPattern); + if (doRefreshFields && !skip_field_refresh) { + await ip.refreshFields(indexPattern); + } + return res.ok({ body: JSON.stringify({ index_pattern: indexPattern.toSpec(), From 544f2be4553634b87f9aa84b660e67984a69c956 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 15:50:13 +0000 Subject: [PATCH 20/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20add=20index?= =?UTF-8?q?=20pattern=20update=20endpoint=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index 3554f8310baa4..da862ba38cf29 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -55,6 +55,7 @@ Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - `POST /api/index_patterns/index_pattern` — create an index pattern - `GET /api/index_patterns/index_pattern/{id}` — fetch an index pattern by `{id}` - `DELETE /api/index_patterns/index_pattern/{id}` — delete an index pattern by `{id}` +- `POST /api/index_patterns/index_pattern/{id}` — partialy update index pattern by `{id}` #### Create an index pattern @@ -160,6 +161,63 @@ DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Returns an '200 OK` response with empty body on success. +### Partialy update index pattern + +Update part of an index pattern. Only provided fields will be updated on the +index pattern, missing fields will stay as they are persisted. + +Update a title of an index pattern. + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +{ + "index_pattern": { + "title": "new_title" + } +} +``` + +All update fields are optional, you can specify the following fields. + +``` +POST /api/index_patterns/index_pattern +{ + "index_pattern": { + "title": "...", + "timeFieldName": "...", + "intervalName": "...", + "sourceFilters": [], + "fieldFormats": {}, + "type": "...", + "typeMeta": {}, + "fields": {} + } +} +``` + +When you are updating fields, you can skip field refresh using `skip_field_refresh` flag. + +``` +POST /api/index_patterns/index_pattern +{ + "skip_field_refresh": true, + "index_pattern": { + "fields": {} + } +} +``` + +This endpoint returns the updated index pattern object. + +```json +{ + "index_pattern": { + + } +} +``` + + ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. From 01994bea1e72c37ef96316ba7dc8cbfacfbf0f5e Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 15:51:02 +0000 Subject: [PATCH 21/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index da862ba38cf29..3eb54868a2d93 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -55,7 +55,7 @@ Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - `POST /api/index_patterns/index_pattern` — create an index pattern - `GET /api/index_patterns/index_pattern/{id}` — fetch an index pattern by `{id}` - `DELETE /api/index_patterns/index_pattern/{id}` — delete an index pattern by `{id}` -- `POST /api/index_patterns/index_pattern/{id}` — partialy update index pattern by `{id}` +- `POST /api/index_patterns/index_pattern/{id}` — partially update index pattern by `{id}` #### Create an index pattern @@ -161,7 +161,7 @@ DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Returns an '200 OK` response with empty body on success. -### Partialy update index pattern +### Partially update index pattern Update part of an index pattern. Only provided fields will be updated on the index pattern, missing fields will stay as they are persisted. @@ -212,7 +212,7 @@ This endpoint returns the updated index pattern object. ```json { "index_pattern": { - + } } ``` From 21f79b9dad773a6938204d6b39bacd3bb6544cf0 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 19 Nov 2020 16:43:57 +0000 Subject: [PATCH 22/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20disable=20XSRF=20a?= =?UTF-8?q?nd=20add=20Content-Type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/index_patterns/routes/create_index_pattern.ts | 6 ++++++ .../server/index_patterns/routes/delete_index_pattern.ts | 9 ++++++++- .../server/index_patterns/routes/get_index_pattern.ts | 3 +++ .../server/index_patterns/routes/update_index_pattern.ts | 6 ++++++ .../server/index_patterns/routes/util/handle_errors.ts | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index ca16aac983d68..e348dec94ce57 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -62,6 +62,9 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { index_pattern: indexPatternSpecSchema, }), }, + options: { + xsrfRequired: false, + }, }, router.handleLegacyErrors( handleErrors( @@ -76,6 +79,9 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { ); return res.ok({ + headers: { + 'content-type': 'application/json', + }, body: JSON.stringify({ index_pattern: indexPattern.toSpec(), }), diff --git a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts index f7510d9b00b7b..b412f79439aa3 100644 --- a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts @@ -37,6 +37,9 @@ export const registerDeleteIndexPatternRoute = (router: IRouter) => { { unknowns: 'allow' } ), }, + options: { + xsrfRequired: false, + }, }, router.handleLegacyErrors( handleErrors( @@ -46,7 +49,11 @@ export const registerDeleteIndexPatternRoute = (router: IRouter) => { await ip.delete(id); - return res.ok(); + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + }); }) ) ) diff --git a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts index bea08ab641895..6de77d773a91f 100644 --- a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts @@ -46,6 +46,9 @@ export const registerGetIndexPatternRoute = (router: IRouter) => { const indexPattern = await ip.get(id); return res.ok({ + headers: { + 'content-type': 'application/json', + }, body: JSON.stringify({ index_pattern: indexPattern.toSpec(), }), diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 1aaac1b50df05..e84ff22196898 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -59,6 +59,9 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { index_pattern: indexPatternUpdateSchema, }), }, + options: { + xsrfRequired: false, + }, }, router.handleLegacyErrors( handleErrors( @@ -142,6 +145,9 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { } return res.ok({ + headers: { + 'content-type': 'application/json', + }, body: JSON.stringify({ index_pattern: indexPattern.toSpec(), }), diff --git a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts index 80ee13614977c..5d3790b0eb783 100644 --- a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts +++ b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts @@ -55,6 +55,9 @@ export const handleErrors = ( } return response.badRequest({ + headers: { + 'content-type': 'application/json', + }, body, }); } From e56c89f4e251c236e05a8569ed2c3a4fc94b1bef Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 13:51:18 +0000 Subject: [PATCH 23/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20enable=20xsrf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes/create_index_pattern.ts | 3 --- .../data/server/index_patterns/routes/delete_index_pattern.ts | 3 --- .../data/server/index_patterns/routes/update_index_pattern.ts | 3 --- 3 files changed, 9 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index e348dec94ce57..ea8a2e06964fd 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -62,9 +62,6 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { index_pattern: indexPatternSpecSchema, }), }, - options: { - xsrfRequired: false, - }, }, router.handleLegacyErrors( handleErrors( diff --git a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts index b412f79439aa3..33562c25e54c0 100644 --- a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts @@ -37,9 +37,6 @@ export const registerDeleteIndexPatternRoute = (router: IRouter) => { { unknowns: 'allow' } ), }, - options: { - xsrfRequired: false, - }, }, router.handleLegacyErrors( handleErrors( diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index e84ff22196898..4862d32a5fcd5 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -59,9 +59,6 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { index_pattern: indexPatternUpdateSchema, }), }, - options: { - xsrfRequired: false, - }, }, router.handleLegacyErrors( handleErrors( From 7eb224e2bfd5a70d9a74f35eb3783005a3ab18a4 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 14:36:24 +0000 Subject: [PATCH 24/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20send=20404=20statu?= =?UTF-8?q?s=20code=20when=20index=20pattern=20is=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/routes/create_index_pattern.ts | 3 ++- .../index_patterns/routes/util/handle_errors.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index ea8a2e06964fd..c95d2b8c7469d 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -18,6 +18,7 @@ */ import { schema } from '@kbn/config-schema'; +import { IndexPatternSpec } from 'src/plugins/data/common'; import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; @@ -69,7 +70,7 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { const ip = ctx.indexPatterns.indexPatterns; const body = req.body; const indexPattern = await ip.createAndSave( - body.index_pattern, + body.index_pattern as IndexPatternSpec, body.override || false, body.skip_field_refresh || false, body.make_default || true diff --git a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts index 5d3790b0eb783..b3f307471cb38 100644 --- a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts +++ b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts @@ -54,6 +54,17 @@ export const handleErrors = ( body.attributes = (error as ErrorWithData).data; } + const is404 = (error as any)?.output?.statusCode === 404; + + if (is404) { + return response.notFound({ + headers: { + 'content-type': 'application/json', + }, + body, + }); + } + return response.badRequest({ headers: { 'content-type': 'application/json', From 15e415093fc65a1e4a8bee5f4bbf3dd4254aad3f Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 14:46:20 +0000 Subject: [PATCH 25/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20correctly=20report?= =?UTF-8?q?=20empty=20change=20set=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/index_patterns/routes/update_index_pattern.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 4862d32a5fcd5..6b08583a8a9d0 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -128,11 +128,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { } if (changeCount < 1) { - return res.badRequest({ - body: JSON.stringify({ - message: 'Index pattern chagne set is empty.', - }), - }); + throw new Error('Index pattern change set is empty.'); } await ip.updateSavedObject(indexPattern); From 6094e3d5151a4d9a6fbb122a8e6263801ca7908f Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 15:15:31 +0000 Subject: [PATCH 26/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20fields=20API=20add?= =?UTF-8?q?=20route=20for=20adding=20field=20to=20IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes.ts | 2 + .../routes/fields/create_field.ts | 82 +++++++++++++++++++ .../index_patterns/routes/util/schemas.ts | 28 +++++-- 3 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/fields/create_field.ts diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 333595b05ce99..9e4ea23160f1c 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -24,6 +24,7 @@ import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; import { registerDeleteIndexPatternRoute } from './routes/delete_index_pattern'; import { registerUpdateIndexPatternRoute } from './routes/update_index_pattern'; +import { registerCreateFieldRoute } from './routes/fields/create_field'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -42,6 +43,7 @@ export function registerRoutes(http: HttpServiceSetup) { registerGetIndexPatternRoute(router); registerDeleteIndexPatternRoute(router); registerUpdateIndexPatternRoute(router); + registerCreateFieldRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts new file mode 100644 index 0000000000000..65e6780c5fccb --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts @@ -0,0 +1,82 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../../core/server'; +import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; +import { handleErrors } from '../util/handle_errors'; +import { fieldSpecSchema } from '../util/schemas'; + +export const registerCreateFieldRoute = (router: IRouter) => { + router.post( + { + path: '/api/index_patterns/index_pattern/{id}/field', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + body: schema.object({ + skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + field: fieldSpecSchema, + }), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + skip_field_refresh = false, + field, + } = req.body; + + const indexPattern = await ip.get(id); + + indexPattern.fields.add(field); + + await ip.updateSavedObject(indexPattern); + if (!skip_field_refresh) { + await ip.refreshFields(indexPattern); + } + + const fieldObject = indexPattern.fields.getByName(field.name); + if (!fieldObject) throw new Error(`Could not create field [name = ${field.name}].`); + + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: fieldObject.toSpec(), + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) + ) + ); +}; diff --git a/src/plugins/data/server/index_patterns/routes/util/schemas.ts b/src/plugins/data/server/index_patterns/routes/util/schemas.ts index 5e7dc985ea5c6..fcb4cd0987b81 100644 --- a/src/plugins/data/server/index_patterns/routes/util/schemas.ts +++ b/src/plugins/data/server/index_patterns/routes/util/schemas.ts @@ -25,13 +25,29 @@ export const serializedFieldFormatSchema = schema.object({ }); export const fieldSpecSchema = schema.object({ - name: schema.string(), - type: schema.string(), + name: schema.string({ + maxLength: 1_000, + }), + type: schema.string({ + maxLength: 1_000, + }), searchable: schema.boolean(), aggregatable: schema.boolean(), - count: schema.maybe(schema.number()), - script: schema.maybe(schema.string()), - lang: schema.maybe(schema.string()), + count: schema.maybe( + schema.number({ + min: 0, + }) + ), + script: schema.maybe( + schema.string({ + maxLength: 1_000_000, + }) + ), + lang: schema.maybe( + schema.string({ + maxLength: 1_000, + }) + ), conflictDescriptions: schema.maybe( schema.recordOf(schema.string(), schema.arrayOf(schema.string())) ), @@ -54,6 +70,6 @@ export const fieldSpecSchema = schema.object({ }) ), indexed: schema.maybe(schema.boolean()), - customName: schema.maybe(schema.string()), + customLabel: schema.maybe(schema.string()), shortDotsEnable: schema.maybe(schema.boolean()), }); From e2d6c5d64a4a32dccc5e7c9b07263c86bb302bc5 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 15:38:53 +0000 Subject: [PATCH 27/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20add=20index?= =?UTF-8?q?=20pattern=20field=20create=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 70 +++++++++++++++++-- .../routes/fields/create_field.ts | 2 +- .../index_patterns/routes/util/schemas.ts | 5 +- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index 3eb54868a2d93..b8462597683e7 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -52,10 +52,25 @@ Coming soon. Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: -- `POST /api/index_patterns/index_pattern` — create an index pattern -- `GET /api/index_patterns/index_pattern/{id}` — fetch an index pattern by `{id}` -- `DELETE /api/index_patterns/index_pattern/{id}` — delete an index pattern by `{id}` -- `POST /api/index_patterns/index_pattern/{id}` — partially update index pattern by `{id}` +- Create an index pattern — `POST /api/index_patterns/index_pattern` +- Fetch an index pattern by `{id}` — `GET /api/index_patterns/index_pattern/{id}` +- Delete an index pattern by `{id}` — `DELETE /api/index_patterns/index_pattern/{id}` +- Partially update an index pattern by `{id}` — `POST /api/index_patterns/index_pattern/{id}` + - `title` + - `timeFieldName` + - `intervalName` + - `fields` + - Optionally refresh fields. + - `sourceFilters` + - `fieldFormatMap` + - `type` + - `typeMeta` +- Fields API + - Create a field — `POST /api/index_patterns/index_pattern/{id}/field` + - Read a new field — `GET /api/index_patterns/index_pattern/{id}/field/{name}` + - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/field/{name}` + - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/field/{name}` + - Remove a field — `DELETE /api/index_patterns/index_pattern/{id}/field/{name}` #### Create an index pattern @@ -161,7 +176,7 @@ DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Returns an '200 OK` response with empty body on success. -### Partially update index pattern +### Partially update an index pattern by ID Update part of an index pattern. Only provided fields will be updated on the index pattern, missing fields will stay as they are persisted. @@ -218,6 +233,51 @@ This endpoint returns the updated index pattern object. ``` +### Fields API + +Fields allows you to manage fields of an existing index pattern. + + +#### Create a field + +Create a field by simply specifying its name, will default to `string` type. + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +{ + "field": { + "name": "my_field" + } +} +``` + +Create a field by specifying all field properties. + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +{ + "field": { + "name": "", + "type": "", + "searchable": false, + "aggregatable": false, + "count": 0, + "script": "", + "scripted": false, + "lang": "", + "conflictDescriptions": {}, + "format": {}, + "esTypes": [], + "readFromDocValues": false, + "subType": {}, + "indexed": false, + "customLabel": "", + "shortDotsEnable": false + } +} +``` + + ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. diff --git a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts index 65e6780c5fccb..85652c04f6bb2 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts @@ -64,7 +64,7 @@ export const registerCreateFieldRoute = (router: IRouter) => { } const fieldObject = indexPattern.fields.getByName(field.name); - if (!fieldObject) throw new Error(`Could not create field [name = ${field.name}].`); + if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); return res.ok({ headers: { diff --git a/src/plugins/data/server/index_patterns/routes/util/schemas.ts b/src/plugins/data/server/index_patterns/routes/util/schemas.ts index fcb4cd0987b81..7f28a82eb96e6 100644 --- a/src/plugins/data/server/index_patterns/routes/util/schemas.ts +++ b/src/plugins/data/server/index_patterns/routes/util/schemas.ts @@ -29,10 +29,11 @@ export const fieldSpecSchema = schema.object({ maxLength: 1_000, }), type: schema.string({ + defaultValue: 'string', maxLength: 1_000, }), - searchable: schema.boolean(), - aggregatable: schema.boolean(), + searchable: schema.boolean({ defaultValue: false }), + aggregatable: schema.boolean({ defaultValue: false }), count: schema.maybe( schema.number({ min: 0, From d53b5aa5892cb7869d3c04e3e9ba4c0630cb31a9 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 15:41:31 +0000 Subject: [PATCH 28/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20throw=20on=20creati?= =?UTF-8?q?ng=20an=20existing=20index=20pattern=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes/fields/create_field.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts index 85652c04f6bb2..b6e07cf39c893 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts @@ -56,6 +56,10 @@ export const registerCreateFieldRoute = (router: IRouter) => { const indexPattern = await ip.get(id); + if (indexPattern.fields.getByName(field.name)) { + throw new Error(`Field [name = ${field.name}] already exists.`); + } + indexPattern.fields.add(field); await ip.updateSavedObject(indexPattern); From 7e2ded6e47738cc9b50ea59d33825c02b3630cca Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 16:03:12 +0000 Subject: [PATCH 29/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20field=20upse?= =?UTF-8?q?rt=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 47 +++++++++- .../data/server/index_patterns/routes.ts | 2 + .../index_patterns/routes/fields/put_field.ts | 87 +++++++++++++++++++ 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/fields/put_field.ts diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index b8462597683e7..a11f465cc7e0e 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -67,9 +67,9 @@ Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - `typeMeta` - Fields API - Create a field — `POST /api/index_patterns/index_pattern/{id}/field` + - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/field` - Read a new field — `GET /api/index_patterns/index_pattern/{id}/field/{name}` - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/field/{name}` - - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/field/{name}` - Remove a field — `DELETE /api/index_patterns/index_pattern/{id}/field/{name}` #### Create an index pattern @@ -240,7 +240,8 @@ Fields allows you to manage fields of an existing index pattern. #### Create a field -Create a field by simply specifying its name, will default to `string` type. +Create a field by simply specifying its name, will default to `string` type. Returns +an error if a field with the provided name already exists. ``` POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field @@ -278,6 +279,48 @@ POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fiel ``` +#### Upsert a field + +Creates a new field or updates an existing one, if one already exists with the same name. + +Create a field by simply specifying its name. + +``` +PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +{ + "field": { + "name": "my_field" + } +} +``` + +Create a field by specifying all field properties. + +``` +PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +{ + "field": { + "name": "", + "type": "", + "searchable": false, + "aggregatable": false, + "count": 0, + "script": "", + "scripted": false, + "lang": "", + "conflictDescriptions": {}, + "format": {}, + "esTypes": [], + "readFromDocValues": false, + "subType": {}, + "indexed": false, + "customLabel": "", + "shortDotsEnable": false + } +} +``` + + ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 9e4ea23160f1c..23356c6c314ab 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -25,6 +25,7 @@ import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; import { registerDeleteIndexPatternRoute } from './routes/delete_index_pattern'; import { registerUpdateIndexPatternRoute } from './routes/update_index_pattern'; import { registerCreateFieldRoute } from './routes/fields/create_field'; +import { registerPutFieldRoute } from './routes/fields/put_field'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -44,6 +45,7 @@ export function registerRoutes(http: HttpServiceSetup) { registerDeleteIndexPatternRoute(router); registerUpdateIndexPatternRoute(router); registerCreateFieldRoute(router); + registerPutFieldRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/put_field.ts b/src/plugins/data/server/index_patterns/routes/fields/put_field.ts new file mode 100644 index 0000000000000..caad51869b427 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/fields/put_field.ts @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../../core/server'; +import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; +import { handleErrors } from '../util/handle_errors'; +import { fieldSpecSchema } from '../util/schemas'; + +export const registerPutFieldRoute = (router: IRouter) => { + router.put( + { + path: '/api/index_patterns/index_pattern/{id}/field', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + body: schema.object({ + skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + field: fieldSpecSchema, + }), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + skip_field_refresh = false, + field, + } = req.body; + + const indexPattern = await ip.get(id); + + const oldFieldObject = indexPattern.fields.getByName(field.name); + if (!!oldFieldObject) { + indexPattern.fields.remove(oldFieldObject); + } + + indexPattern.fields.add(field); + + await ip.updateSavedObject(indexPattern); + if (!skip_field_refresh) { + await ip.refreshFields(indexPattern); + } + + const fieldObject = indexPattern.fields.getByName(field.name); + if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); + + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: fieldObject.toSpec(), + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) + ) + ); +}; From bc7dc4a08d4cdbff56402922be7eaf7693b332be Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 16:35:35 +0000 Subject: [PATCH 30/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20field=20get?= =?UTF-8?q?=20api=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 19 ++++- .../data/server/index_patterns/routes.ts | 2 + .../index_patterns/routes/fields/get_field.ts | 78 +++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/plugins/data/server/index_patterns/routes/fields/get_field.ts diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index a11f465cc7e0e..d8f64ccae2019 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -68,7 +68,7 @@ Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - Fields API - Create a field — `POST /api/index_patterns/index_pattern/{id}/field` - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/field` - - Read a new field — `GET /api/index_patterns/index_pattern/{id}/field/{name}` + - Fetch a field — `GET /api/index_patterns/index_pattern/{id}/field/{name}` - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/field/{name}` - Remove a field — `DELETE /api/index_patterns/index_pattern/{id}/field/{name}` @@ -321,6 +321,23 @@ PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field ``` +#### Fetch a field + +Fetch an existing index pattern field by field name. + +``` +GET /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/ +``` + +Returns the field object. + +```json +{ + "field": {} +} +``` + + ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 23356c6c314ab..66fdeeb1d941c 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -26,6 +26,7 @@ import { registerDeleteIndexPatternRoute } from './routes/delete_index_pattern'; import { registerUpdateIndexPatternRoute } from './routes/update_index_pattern'; import { registerCreateFieldRoute } from './routes/fields/create_field'; import { registerPutFieldRoute } from './routes/fields/put_field'; +import { registerGetFieldRoute } from './routes/fields/get_field'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -46,6 +47,7 @@ export function registerRoutes(http: HttpServiceSetup) { registerUpdateIndexPatternRoute(router); registerCreateFieldRoute(router); registerPutFieldRoute(router); + registerGetFieldRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts new file mode 100644 index 0000000000000..ede01c3c30950 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts @@ -0,0 +1,78 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../../core/server'; +import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; +import { handleErrors } from '../util/handle_errors'; + +export const registerGetFieldRoute = (router: IRouter) => { + router.get( + { + path: '/api/index_patterns/index_pattern/{id}/field/{name}', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + name: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const name = req.params.name; + + const indexPattern = await ip.get(id); + const field = indexPattern.fields.getByName(name); + + if (!field) { + return res.notFound({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + message: 'Not found', + }), + }); + } + + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: field.toSpec(), + }), + }); + }) + ) + ) + ); +}; From 8e785c77b3300b2deb9f6a8d0a2e651f8ee1b5ed Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 16:44:25 +0000 Subject: [PATCH 31/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20field=20dele?= =?UTF-8?q?te=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 11 ++- .../data/server/index_patterns/routes.ts | 2 + .../routes/fields/delete_field.ts | 74 +++++++++++++++++++ .../index_patterns/routes/fields/get_field.ts | 11 +-- 4 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/fields/delete_field.ts diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index d8f64ccae2019..33fb63203963c 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -237,7 +237,6 @@ This endpoint returns the updated index pattern object. Fields allows you to manage fields of an existing index pattern. - #### Create a field Create a field by simply specifying its name, will default to `string` type. Returns @@ -278,7 +277,6 @@ POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fiel } ``` - #### Upsert a field Creates a new field or updates an existing one, if one already exists with the same name. @@ -320,7 +318,6 @@ PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field } ``` - #### Fetch a field Fetch an existing index pattern field by field name. @@ -337,6 +334,14 @@ Returns the field object. } ``` +#### Delete a field + +Delete a field of an index pattern. + +``` +DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/ +``` + ## Query diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 66fdeeb1d941c..35c39af826a40 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -27,6 +27,7 @@ import { registerUpdateIndexPatternRoute } from './routes/update_index_pattern'; import { registerCreateFieldRoute } from './routes/fields/create_field'; import { registerPutFieldRoute } from './routes/fields/put_field'; import { registerGetFieldRoute } from './routes/fields/get_field'; +import { registerDeleteFieldRoute } from './routes/fields/delete_field'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -48,6 +49,7 @@ export function registerRoutes(http: HttpServiceSetup) { registerCreateFieldRoute(router); registerPutFieldRoute(router); registerGetFieldRoute(router); + registerDeleteFieldRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts new file mode 100644 index 0000000000000..c765736179a09 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts @@ -0,0 +1,74 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../../core/server'; +import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; +import { handleErrors } from '../util/handle_errors'; + +export const registerDeleteFieldRoute = (router: IRouter) => { + router.delete( + { + path: '/api/index_patterns/index_pattern/{id}/field/{name}', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + name: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const name = req.params.name; + + const indexPattern = await ip.get(id); + const field = indexPattern.fields.getByName(name); + + if (!field) { + const error = new Error(`Field [indexPattern.id = ${id}, field = ${name}] not found.`); + (error as any).output = { statusCode: 404 }; + throw error; + } + + indexPattern.fields.remove(field); + + await ip.updateSavedObject(indexPattern); + + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + }); + }) + ) + ) + ); +}; diff --git a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts index ede01c3c30950..0368c0ab8f91a 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts @@ -53,14 +53,9 @@ export const registerGetFieldRoute = (router: IRouter) => { const field = indexPattern.fields.getByName(name); if (!field) { - return res.notFound({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - message: 'Not found', - }), - }); + const error = new Error(`Field [indexPattern.id = ${id}, field = ${name}] not found.`); + (error as any).output = { statusCode: 404 }; + throw error; } return res.ok({ From aa94b96ebe3aace3db7f8ebfd972ea51fb96e7eb Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 16:56:44 +0000 Subject: [PATCH 32/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20improve=20404?= =?UTF-8?q?=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/public/plugin.ts | 10 ------- .../data/server/index_patterns/error.ts | 28 +++++++++++++++++++ .../routes/fields/delete_field.ts | 7 +++-- .../index_patterns/routes/fields/get_field.ts | 7 +++-- .../routes/util/handle_errors.ts | 4 ++- 5 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/error.ts diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 269a744ecaf33..7e8283476ffc5 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -225,16 +225,6 @@ export class DataPublicPlugin trackUiMetric: this.usageCollection?.reportUiStats.bind(this.usageCollection, 'data_plugin'), }); - // core.http - // .fetch('/api/index_patterns/index_pattern', { - // method: 'POST', - // body: JSON.stringify({ - // name: 'test', - // }), - // }) - // .then((val) => console.log('val', val)) - // .catch((err) => console.log('err', err)); - return { ...dataServices, ui: { diff --git a/src/plugins/data/server/index_patterns/error.ts b/src/plugins/data/server/index_patterns/error.ts new file mode 100644 index 0000000000000..a3b2cd6ac5d53 --- /dev/null +++ b/src/plugins/data/server/index_patterns/error.ts @@ -0,0 +1,28 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export class ErrorIndexPatternNotFound extends Error { + public readonly is404 = true; + + constructor(message: string) { + super(message); + + Object.setPrototypeOf(this, ErrorIndexPatternNotFound.prototype); + } +} diff --git a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts index c765736179a09..7a6ed2a4fc0bc 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts @@ -19,6 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; +import { ErrorIndexPatternNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; @@ -53,9 +54,9 @@ export const registerDeleteFieldRoute = (router: IRouter) => { const field = indexPattern.fields.getByName(name); if (!field) { - const error = new Error(`Field [indexPattern.id = ${id}, field = ${name}] not found.`); - (error as any).output = { statusCode: 404 }; - throw error; + throw new ErrorIndexPatternNotFound( + `Field [indexPattern.id = ${id}, field = ${name}] not found.` + ); } indexPattern.fields.remove(field); diff --git a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts index 0368c0ab8f91a..65491b41cec29 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts @@ -19,6 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; +import { ErrorIndexPatternNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; @@ -53,9 +54,9 @@ export const registerGetFieldRoute = (router: IRouter) => { const field = indexPattern.fields.getByName(name); if (!field) { - const error = new Error(`Field [indexPattern.id = ${id}, field = ${name}] not found.`); - (error as any).output = { statusCode: 404 }; - throw error; + throw new ErrorIndexPatternNotFound( + `Field [indexPattern.id = ${id}, field = ${name}] not found.` + ); } return res.ok({ diff --git a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts index b3f307471cb38..82e2a256bef73 100644 --- a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts +++ b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts @@ -18,6 +18,7 @@ */ import { RequestHandler, RouteMethod } from 'src/core/server'; +import { ErrorIndexPatternNotFound } from '../../error'; interface ErrorResponseBody { message: string; @@ -54,7 +55,8 @@ export const handleErrors = ( body.attributes = (error as ErrorWithData).data; } - const is404 = (error as any)?.output?.statusCode === 404; + const is404 = + (error as ErrorIndexPatternNotFound).is404 || (error as any)?.output?.statusCode === 404; if (is404) { return response.notFound({ From 6b6a0ad5e835b69de5388059b84f5bfae0681171 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 17:12:49 +0000 Subject: [PATCH 33/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20improve=20inde?= =?UTF-8?q?x=20pattern=20404=20error=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/server/index_patterns/error.ts | 8 ++++++++ .../server/index_patterns/routes/fields/delete_field.ts | 6 ++---- .../data/server/index_patterns/routes/fields/get_field.ts | 6 ++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/plugins/data/server/index_patterns/error.ts b/src/plugins/data/server/index_patterns/error.ts index a3b2cd6ac5d53..3e369d3275d9a 100644 --- a/src/plugins/data/server/index_patterns/error.ts +++ b/src/plugins/data/server/index_patterns/error.ts @@ -17,6 +17,8 @@ * under the License. */ +/* eslint-disable max-classes-per-file */ + export class ErrorIndexPatternNotFound extends Error { public readonly is404 = true; @@ -26,3 +28,9 @@ export class ErrorIndexPatternNotFound extends Error { Object.setPrototypeOf(this, ErrorIndexPatternNotFound.prototype); } } + +export class ErrorIndexPatternFieldNotFound extends ErrorIndexPatternNotFound { + constructor(indexPatternId: string, fieldName: string) { + super(`Field [index_pattern = ${indexPatternId}, field = ${fieldName}] not found.`); + } +} diff --git a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts index 7a6ed2a4fc0bc..5f2a3bc099d00 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts @@ -19,7 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; -import { ErrorIndexPatternNotFound } from '../../error'; +import { ErrorIndexPatternFieldNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; @@ -54,9 +54,7 @@ export const registerDeleteFieldRoute = (router: IRouter) => { const field = indexPattern.fields.getByName(name); if (!field) { - throw new ErrorIndexPatternNotFound( - `Field [indexPattern.id = ${id}, field = ${name}] not found.` - ); + throw new ErrorIndexPatternFieldNotFound(id, name); } indexPattern.fields.remove(field); diff --git a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts index 65491b41cec29..01bd6ddd5f540 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts @@ -19,7 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; -import { ErrorIndexPatternNotFound } from '../../error'; +import { ErrorIndexPatternFieldNotFound, ErrorIndexPatternNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; @@ -54,9 +54,7 @@ export const registerGetFieldRoute = (router: IRouter) => { const field = indexPattern.fields.getByName(name); if (!field) { - throw new ErrorIndexPatternNotFound( - `Field [indexPattern.id = ${id}, field = ${name}] not found.` - ); + throw new ErrorIndexPatternFieldNotFound(id, name); } return res.ok({ From 3b35afa6c4720f52036e1594e7e27f016ff26a75 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 17:23:05 +0000 Subject: [PATCH 34/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20field=20upda?= =?UTF-8?q?te=20api=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 32 ++++- .../data/server/index_patterns/routes.ts | 2 + .../routes/fields/update_field.ts | 116 ++++++++++++++++++ .../index_patterns/routes/util/schemas.ts | 6 +- 4 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/fields/update_field.ts diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index 33fb63203963c..e08f10276d594 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -69,8 +69,8 @@ Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - Create a field — `POST /api/index_patterns/index_pattern/{id}/field` - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/field` - Fetch a field — `GET /api/index_patterns/index_pattern/{id}/field/{name}` - - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/field/{name}` - Remove a field — `DELETE /api/index_patterns/index_pattern/{id}/field/{name}` + - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/field/{name}` #### Create an index pattern @@ -342,6 +342,36 @@ Delete a field of an index pattern. DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/ ``` +#### Update a an existing field + +Updates an exiting field by mergin provided properties with the existing ones. If +there is no existing field with the specified name, returns a `404 Not Found` error. + +You can specify any field properties, except `name` which is specified in the URL path. + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/{name} +{ + "field": { + "type": "", + "searchable": false, + "aggregatable": false, + "count": 0, + "script": "", + "scripted": false, + "lang": "", + "conflictDescriptions": {}, + "format": {}, + "esTypes": [], + "readFromDocValues": false, + "subType": {}, + "indexed": false, + "customLabel": "", + "shortDotsEnable": false + } +} +``` + ## Query diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 35c39af826a40..d53465be16aba 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -28,6 +28,7 @@ import { registerCreateFieldRoute } from './routes/fields/create_field'; import { registerPutFieldRoute } from './routes/fields/put_field'; import { registerGetFieldRoute } from './routes/fields/get_field'; import { registerDeleteFieldRoute } from './routes/fields/delete_field'; +import { registerUpdateFieldRoute } from './routes/fields/update_field'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -50,6 +51,7 @@ export function registerRoutes(http: HttpServiceSetup) { registerPutFieldRoute(router); registerGetFieldRoute(router); registerDeleteFieldRoute(router); + registerUpdateFieldRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts b/src/plugins/data/server/index_patterns/routes/fields/update_field.ts new file mode 100644 index 0000000000000..811fd80c07618 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/fields/update_field.ts @@ -0,0 +1,116 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { FieldSpec } from 'src/plugins/data/common'; +import { IRouter } from '../../../../../../core/server'; +import { ErrorIndexPatternFieldNotFound } from '../../error'; +import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; +import { handleErrors } from '../util/handle_errors'; +import { fieldSpecSchemaFields } from '../util/schemas'; + +export const registerUpdateFieldRoute = (router: IRouter) => { + router.post( + { + path: '/api/index_patterns/index_pattern/{id}/field/{name}', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + name: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + body: schema.object({ + skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + field: schema.object({ + ...fieldSpecSchemaFields, + + // We need to overwrite the below fields on top of `fieldSpecSchemaFields`, + // because `name` field must not appear here and other below fields + // should be possible to not provide `schema.maybe()` instead of + // them being required with a default value in `fieldSpecSchemaFields`. + name: schema.never(), + type: schema.maybe( + schema.string({ + maxLength: 1_000, + }) + ), + searchable: schema.maybe(schema.boolean()), + aggregatable: schema.maybe(schema.boolean()), + }), + }), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const name = req.params.name; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + skip_field_refresh = false, + } = req.body; + + const field = ({ ...req.body.field, name } as unknown) as FieldSpec; + + const indexPattern = await ip.get(id); + let fieldObject = indexPattern.fields.getByName(field.name); + + if (!fieldObject) { + throw new ErrorIndexPatternFieldNotFound(id, name); + } + + const oldSpec = fieldObject.toSpec(); + + indexPattern.fields.remove(fieldObject); + indexPattern.fields.add({ + ...oldSpec, + ...field, + }); + + await ip.updateSavedObject(indexPattern); + if (!skip_field_refresh) { + await ip.refreshFields(indexPattern); + } + + fieldObject = indexPattern.fields.getByName(field.name); + if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); + + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: fieldObject.toSpec(), + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) + ) + ); +}; diff --git a/src/plugins/data/server/index_patterns/routes/util/schemas.ts b/src/plugins/data/server/index_patterns/routes/util/schemas.ts index 7f28a82eb96e6..dbfddb28d1ed6 100644 --- a/src/plugins/data/server/index_patterns/routes/util/schemas.ts +++ b/src/plugins/data/server/index_patterns/routes/util/schemas.ts @@ -24,7 +24,7 @@ export const serializedFieldFormatSchema = schema.object({ params: schema.maybe(schema.any()), }); -export const fieldSpecSchema = schema.object({ +export const fieldSpecSchemaFields = { name: schema.string({ maxLength: 1_000, }), @@ -73,4 +73,6 @@ export const fieldSpecSchema = schema.object({ indexed: schema.maybe(schema.boolean()), customLabel: schema.maybe(schema.string()), shortDotsEnable: schema.maybe(schema.boolean()), -}); +}; + +export const fieldSpecSchema = schema.object(fieldSpecSchemaFields); From 660d24da312d44920623c0d907f1b484fc98a0a5 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 20 Nov 2020 17:27:10 +0000 Subject: [PATCH 35/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index e08f10276d594..ecb5273645d56 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -350,7 +350,7 @@ there is no existing field with the specified name, returns a `404 Not Found` er You can specify any field properties, except `name` which is specified in the URL path. ``` -POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/{name} +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/ { "field": { "type": "", From d5ddd53321e5dbbdb7421ed3e2d6b8d911a44be2 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 11:26:54 +0000 Subject: [PATCH 36/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20rename=20ski?= =?UTF-8?q?=5Ffield=5Frefresh=20to=20refresh=5Ffields=20in=20creat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 6 +++--- .../server/index_patterns/routes/create_index_pattern.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index ecb5273645d56..bd0d2becc9b11 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -89,8 +89,8 @@ Customize creation behavior with: - `override` --- if set to `true`, replaces an existing index pattern if an index pattern with the provided title already exists. Defaults to `false`. -- `skip_field_refresh` --- if set to `true` skips reloading index pattern fields after - the index pattern is stored. Defaults to `false`. +- `refresh_fields` --- if set to `false` skips reloading index pattern fields after + the index pattern is stored. Defaults to `true`. - `make_default` --- if set to `true`, makes the new index pattern the default index pattern. Defaults to `true`. @@ -98,7 +98,7 @@ Customize creation behavior with: POST /api/index_patterns/index_pattern { "override": false, - "skip_field_refresh": false, + "refresh_fields": true, "make_default": true, "index_pattern": { "title": "hello" diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index c95d2b8c7469d..e0d54d1bcfef8 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -58,7 +58,7 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { validate: { body: schema.object({ override: schema.maybe(schema.boolean({ defaultValue: false })), - skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), make_default: schema.maybe(schema.boolean({ defaultValue: true })), index_pattern: indexPatternSpecSchema, }), @@ -71,9 +71,9 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { const body = req.body; const indexPattern = await ip.createAndSave( body.index_pattern as IndexPatternSpec, - body.override || false, - body.skip_field_refresh || false, - body.make_default || true + body.override, + !body.refresh_fields, + body.make_default ); return res.ok({ From 39527295c7de8221d5f999f48c5976e3731a61ef Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 11:29:32 +0000 Subject: [PATCH 37/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20rename=20to=20?= =?UTF-8?q?refresh=5Ffields=20param=20in=20update=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 5 +++-- .../server/index_patterns/routes/update_index_pattern.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index bd0d2becc9b11..ecff1ddb35d57 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -210,12 +210,13 @@ POST /api/index_patterns/index_pattern } ``` -When you are updating fields, you can skip field refresh using `skip_field_refresh` flag. +When you are updating fields, you can skip field refresh using `refresh_fields` flag. +`refresh_fields` defaults to `true`. ``` POST /api/index_patterns/index_pattern { - "skip_field_refresh": true, + "refresh_fields": false, "index_pattern": { "fields": {} } diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 6b08583a8a9d0..57a9ea982498f 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -55,7 +55,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), index_pattern: indexPatternUpdateSchema, }), }, @@ -70,7 +70,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { const { // eslint-disable-next-line @typescript-eslint/naming-convention - skip_field_refresh = false, + refresh_fields = true, index_pattern: { title, timeFieldName, @@ -133,7 +133,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { await ip.updateSavedObject(indexPattern); - if (doRefreshFields && !skip_field_refresh) { + if (doRefreshFields && refresh_fields) { await ip.refreshFields(indexPattern); } From 8802b3d6a5aa1eed3d387238ce812f4d49f86d58 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 11:32:27 +0000 Subject: [PATCH 38/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20rename=20param?= =?UTF-8?q?eter=20to=20refresh=5Ffields=20in=20fields=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/index_patterns/routes/fields/create_field.ts | 6 +++--- .../data/server/index_patterns/routes/fields/put_field.ts | 6 +++--- .../server/index_patterns/routes/fields/update_field.ts | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts index b6e07cf39c893..6061024e6e733 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts @@ -38,7 +38,7 @@ export const registerCreateFieldRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), field: fieldSpecSchema, }), }, @@ -50,7 +50,7 @@ export const registerCreateFieldRoute = (router: IRouter) => { const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention - skip_field_refresh = false, + refresh_fields = true, field, } = req.body; @@ -63,7 +63,7 @@ export const registerCreateFieldRoute = (router: IRouter) => { indexPattern.fields.add(field); await ip.updateSavedObject(indexPattern); - if (!skip_field_refresh) { + if (refresh_fields) { await ip.refreshFields(indexPattern); } diff --git a/src/plugins/data/server/index_patterns/routes/fields/put_field.ts b/src/plugins/data/server/index_patterns/routes/fields/put_field.ts index caad51869b427..eefa3681372b1 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/put_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/put_field.ts @@ -38,7 +38,7 @@ export const registerPutFieldRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), field: fieldSpecSchema, }), }, @@ -50,7 +50,7 @@ export const registerPutFieldRoute = (router: IRouter) => { const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention - skip_field_refresh = false, + refresh_fields = true, field, } = req.body; @@ -64,7 +64,7 @@ export const registerPutFieldRoute = (router: IRouter) => { indexPattern.fields.add(field); await ip.updateSavedObject(indexPattern); - if (!skip_field_refresh) { + if (refresh_fields) { await ip.refreshFields(indexPattern); } diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts b/src/plugins/data/server/index_patterns/routes/fields/update_field.ts index 811fd80c07618..2a1d01e98ec58 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_field.ts @@ -44,7 +44,7 @@ export const registerUpdateFieldRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - skip_field_refresh: schema.maybe(schema.boolean({ defaultValue: false })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), field: schema.object({ ...fieldSpecSchemaFields, @@ -72,7 +72,7 @@ export const registerUpdateFieldRoute = (router: IRouter) => { const name = req.params.name; const { // eslint-disable-next-line @typescript-eslint/naming-convention - skip_field_refresh = false, + refresh_fields = true, } = req.body; const field = ({ ...req.body.field, name } as unknown) as FieldSpec; @@ -93,7 +93,7 @@ export const registerUpdateFieldRoute = (router: IRouter) => { }); await ip.updateSavedObject(indexPattern); - if (!skip_field_refresh) { + if (refresh_fields) { await ip.refreshFields(indexPattern); } From efbe29687390d04611be1619395df619ada65625 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 12:02:20 +0000 Subject: [PATCH 39/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20allow=20creating?= =?UTF-8?q?=20and=20deleting=20only=20scripted=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes/fields/create_field.ts | 4 ++++ .../data/server/index_patterns/routes/fields/delete_field.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts index 6061024e6e733..9af476e792c63 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/create_field.ts @@ -54,6 +54,10 @@ export const registerCreateFieldRoute = (router: IRouter) => { field, } = req.body; + if (!field.scripted) { + throw new Error('Only scripted fields can be created.'); + } + const indexPattern = await ip.get(id); if (indexPattern.fields.getByName(field.name)) { diff --git a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts index 5f2a3bc099d00..a893c444f092c 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts @@ -57,6 +57,10 @@ export const registerDeleteFieldRoute = (router: IRouter) => { throw new ErrorIndexPatternFieldNotFound(id, name); } + if (!field.scripted) { + throw new Error('Only scripted fields can be deleted.'); + } + indexPattern.fields.remove(field); await ip.updateSavedObject(indexPattern); From 52bf57a9cc8d3362eee66111f4c4ad412586e0b1 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 12:07:12 +0000 Subject: [PATCH 40/93] =?UTF-8?q?style:=20=F0=9F=92=84=20fix=20TypeScript/?= =?UTF-8?q?Prettier=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes/fields/get_field.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts index 01bd6ddd5f540..841fd6829bc04 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/get_field.ts @@ -19,7 +19,7 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; -import { ErrorIndexPatternFieldNotFound, ErrorIndexPatternNotFound } from '../../error'; +import { ErrorIndexPatternFieldNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; From 2143547a68591cf84d2ba25081b6d8be24dcc0a1 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 14:31:00 +0100 Subject: [PATCH 41/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20index=20patt?= =?UTF-8?q?ern=20creation=20negative=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/create_index_pattern.ts | 3 +- .../apis/index_patterns/index.js | 1 + .../create_index_pattern/errors.ts | 94 +++++++++++++++++++ .../create_index_pattern/index.ts | 26 +++++ .../index_pattern_crud/index.ts | 26 +++++ 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/errors.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/index.ts diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index e0d54d1bcfef8..4e25dd8090fe6 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -25,9 +25,10 @@ import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; const indexPatternSpecSchema = schema.object({ + title: schema.string(), + id: schema.maybe(schema.string()), version: schema.maybe(schema.string()), - title: schema.maybe(schema.string()), type: schema.maybe(schema.string()), intervalName: schema.maybe(schema.string()), timeFieldName: schema.maybe(schema.string()), diff --git a/test/api_integration/apis/index_patterns/index.js b/test/api_integration/apis/index_patterns/index.js index 42f907ff8aec1..7208c8c655bfb 100644 --- a/test/api_integration/apis/index_patterns/index.js +++ b/test/api_integration/apis/index_patterns/index.js @@ -22,5 +22,6 @@ export default function ({ loadTestFile }) { loadTestFile(require.resolve('./es_errors')); loadTestFile(require.resolve('./fields_for_time_pattern_route')); loadTestFile(require.resolve('./fields_for_wildcard_route')); + loadTestFile(require.resolve('./index_pattern_crud')); }); } diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/errors.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/errors.ts new file mode 100644 index 0000000000000..d4babd722ef5d --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/errors.ts @@ -0,0 +1,94 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns error when index_pattern object is not provided', async () => { + const response = await supertest.post('/api/index_patterns/index_pattern'); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + '[request body]: expected a plain object value, but found [null] instead.' + ); + }); + + it('returns error on empty index_pattern object', async () => { + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: {}, + }); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + '[request body.index_pattern.title]: expected value of type [string] but got [undefined]' + ); + }); + + it('returns error when "override" parameter is not a boolean', async () => { + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + override: 123, + index_pattern: { + title: 'foo', + }, + }); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + '[request body.override]: expected value of type [boolean] but got [number]' + ); + }); + + it('returns error when "refresh_fields" parameter is not a boolean', async () => { + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + refresh_fields: 123, + index_pattern: { + title: 'foo', + }, + }); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + '[request body.refresh_fields]: expected value of type [boolean] but got [number]' + ); + }); + + it('returns error when "make_default" parameter is not a boolean', async () => { + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + make_default: 123, + index_pattern: { + title: 'foo', + }, + }); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + '[request body.make_default]: expected value of type [boolean] but got [number]' + ); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts new file mode 100644 index 0000000000000..8be6b0add6681 --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('create_index_pattern', () => { + loadTestFile(require.resolve('./errors')); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts new file mode 100644 index 0000000000000..8dde4eff20b68 --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('index_pattern_crud', () => { + loadTestFile(require.resolve('./create_index_pattern')); + }); +} From ac28cae05296b2a33776a791894bc191ccbbdc05 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 15:24:09 +0100 Subject: [PATCH 42/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20index=20patt?= =?UTF-8?q?ern=20create=20method=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_pattern.ts | 2 + .../create_index_pattern/index.ts | 3 +- .../create_index_pattern/main.ts | 261 ++++++++++++++++++ .../{errors.ts => validation.ts} | 2 +- 4 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts rename test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/{errors.ts => validation.ts} (99%) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 47ad5860801bc..104eeb608d550 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -109,6 +109,7 @@ export class IndexPattern implements IIndexPattern { this.type = spec.type; this.typeMeta = spec.typeMeta; this.fieldAttrs = spec.fieldAttrs || {}; + this.intervalName = spec.intervalName; } setFieldFormat = (fieldName: string, format: SerializedFieldFormat) => { @@ -199,6 +200,7 @@ export class IndexPattern implements IIndexPattern { type: this.type, fieldFormats: this.fieldFormatMap, fieldAttrs: this.fieldAttrs, + intervalName: this.intervalName, }; } diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts index 8be6b0add6681..f357d9992d642 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/index.ts @@ -21,6 +21,7 @@ import { FtrProviderContext } from '../../../../ftr_provider_context'; export default function ({ loadTestFile }: FtrProviderContext) { describe('create_index_pattern', () => { - loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./validation')); + loadTestFile(require.resolve('./main')); }); } diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts new file mode 100644 index 0000000000000..45311fed2d31d --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts @@ -0,0 +1,261 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can create an index_pattern with just a title', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + expect(response.status).to.be(200); + }); + + it('returns back the created index_pattern object', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + expect(typeof response.body.index_pattern).to.be('object'); + expect(response.body.index_pattern.title).to.be(title); + expect(typeof response.body.index_pattern.id).to.be('string'); + expect(response.body.index_pattern.id.length > 0).to.be(true); + }); + + it('can specify primitive optional attributes when creating an index pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const id = `test-id-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + id, + version: 'test-version', + type: 'test-type', + intervalName: 'test-intervalName', + timeFieldName: 'test-timeFieldName', + }, + }); + + expect(response.status).to.be(200); + expect(response.body.index_pattern.title).to.be(title); + expect(response.body.index_pattern.id).to.be(id); + expect(response.body.index_pattern.version).to.be('test-version'); + expect(response.body.index_pattern.type).to.be('test-type'); + expect(response.body.index_pattern.intervalName).to.be('test-intervalName'); + expect(response.body.index_pattern.timeFieldName).to.be('test-timeFieldName'); + }); + + it('can specify optional sourceFilters attribute when creating an index pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + sourceFilters: [ + { + value: 'foo', + }, + ], + }, + }); + + expect(response.status).to.be(200); + expect(response.body.index_pattern.title).to.be(title); + expect(response.body.index_pattern.sourceFilters[0].value).to.be('foo'); + }); + + it('can specify optional fields attribute when creating an index pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + searchable: false, + aggregatable: false, + }, + }, + }, + }); + + expect(response.status).to.be(200); + expect(response.body.index_pattern.title).to.be(title); + expect(response.body.index_pattern.fields.foo.name).to.be('foo'); + expect(response.body.index_pattern.fields.foo.type).to.be('string'); + expect(response.body.index_pattern.fields.foo.searchable).to.be(false); + expect(response.body.index_pattern.fields.foo.aggregatable).to.be(false); + }); + + it('can add two fields, one with all fields specified', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + searchable: false, + aggregatable: false, + }, + bar: { + name: 'bar', + type: 'number', + searchable: true, + aggregatable: true, + count: 123, + script: '', + lang: 'test-lang', + conflictDescriptions: { + foo: ['bar'], + }, + esTypes: ['test-type'], + scripted: false, + readFromDocValues: false, + }, + }, + }, + }); + + expect(response.status).to.be(200); + expect(response.body.index_pattern.title).to.be(title); + + expect(response.body.index_pattern.fields.foo.name).to.be('foo'); + expect(response.body.index_pattern.fields.foo.type).to.be('string'); + expect(response.body.index_pattern.fields.foo.searchable).to.be(false); + expect(response.body.index_pattern.fields.foo.aggregatable).to.be(false); + + expect(response.body.index_pattern.fields.bar.name).to.be('bar'); + expect(response.body.index_pattern.fields.bar.type).to.be('number'); + expect(response.body.index_pattern.fields.bar.searchable).to.be(true); + expect(response.body.index_pattern.fields.bar.aggregatable).to.be(true); + expect(response.body.index_pattern.fields.bar.count).to.be(123); + expect(response.body.index_pattern.fields.bar.script).to.be(''); + expect(response.body.index_pattern.fields.bar.lang).to.be('test-lang'); + expect(response.body.index_pattern.fields.bar.conflictDescriptions.foo[0]).to.be('bar'); + expect(response.body.index_pattern.fields.bar.esTypes[0]).to.be('test-type'); + expect(response.body.index_pattern.fields.bar.scripted).to.be(false); + expect(response.body.index_pattern.fields.bar.readFromDocValues).to.be(false); + }); + + it('can specify optional typeMeta attribute when creating an index pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + typeMeta: {}, + }, + }); + + expect(response.status).to.be(200); + }); + + it('can specify optional fieldFormats attribute when creating an index pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldFormats: { + foo: { + id: 'test-id', + params: {}, + }, + }, + }, + }); + + expect(response.status).to.be(200); + expect(response.body.index_pattern.fieldFormats.foo.id).to.be('test-id'); + expect(response.body.index_pattern.fieldFormats.foo.params).to.eql({}); + }); + + it('can specify optional fieldFormats attribute when creating an index pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldAttrs: { + foo: { + customName: 'bar', + }, + }, + }, + }); + + expect(response.status).to.be(200); + expect(response.body.index_pattern.fieldAttrs.foo.customName).to.be('bar'); + }); + + describe('when creating index pattern with existing title', () => { + it('returns error, by default', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const response2 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + expect(response1.status).to.be(200); + expect(response2.status).to.be(400); + }); + + it('succeeds, override flag is set', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + intervalName: 'foo', + }, + }); + const response2 = await supertest.post('/api/index_patterns/index_pattern').send({ + override: true, + index_pattern: { + title, + intervalName: 'bar', + }, + }); + + expect(response1.status).to.be(200); + expect(response2.status).to.be(200); + + expect(response1.body.index_pattern.intervalName).to.be('foo'); + expect(response2.body.index_pattern.intervalName).to.be('bar'); + + expect(response1.body.index_pattern.id).to.be(response1.body.index_pattern.id); + }); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/errors.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/validation.ts similarity index 99% rename from test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/errors.ts rename to test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/validation.ts index d4babd722ef5d..0f34402bc5499 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/errors.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/validation.ts @@ -23,7 +23,7 @@ import { FtrProviderContext } from '../../../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - describe('errors', () => { + describe('validation', () => { it('returns error when index_pattern object is not provided', async () => { const response = await supertest.post('/api/index_patterns/index_pattern'); From 5b71aea7433c254f26141606eeec3f3e40bbe550 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 15:34:14 +0100 Subject: [PATCH 43/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20remove=20make=5Fde?= =?UTF-8?q?fault=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns.ts | 13 ++----------- .../index_patterns/routes/create_index_pattern.ts | 4 +--- .../create_index_pattern/validation.ts | 15 --------------- 3 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index b364cdf73588c..72392f78528fd 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -484,19 +484,10 @@ export class IndexPatternsService { * index pattern. */ - async createAndSave( - spec: IndexPatternSpec, - override = false, - skipFetchFields = false, - makeDefault: boolean = true - ) { + async createAndSave(spec: IndexPatternSpec, override = false, skipFetchFields = false) { const indexPattern = await this.create(spec, skipFetchFields); await this.createSavedObject(indexPattern, override); - - if (makeDefault) { - await this.setDefault(indexPattern.id!); - } - + await this.setDefault(indexPattern.id!); return indexPattern; } diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 4e25dd8090fe6..5265acfad5dc3 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -60,7 +60,6 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { body: schema.object({ override: schema.maybe(schema.boolean({ defaultValue: false })), refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), - make_default: schema.maybe(schema.boolean({ defaultValue: true })), index_pattern: indexPatternSpecSchema, }), }, @@ -73,8 +72,7 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { const indexPattern = await ip.createAndSave( body.index_pattern as IndexPatternSpec, body.override, - !body.refresh_fields, - body.make_default + !body.refresh_fields ); return res.ok({ diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/validation.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/validation.ts index 0f34402bc5499..2b95ee2eac95a 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/validation.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/validation.ts @@ -75,20 +75,5 @@ export default function ({ getService }: FtrProviderContext) { '[request body.refresh_fields]: expected value of type [boolean] but got [number]' ); }); - - it('returns error when "make_default" parameter is not a boolean', async () => { - const response = await supertest.post('/api/index_patterns/index_pattern').send({ - make_default: 123, - index_pattern: { - title: 'foo', - }, - }); - - expect(response.status).to.be(400); - expect(response.body.statusCode).to.be(400); - expect(response.body.message).to.be( - '[request body.make_default]: expected value of type [boolean] but got [number]' - ); - }); }); } From 7058916462eb612827535c67287258e56b664ef8 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 15:47:24 +0100 Subject: [PATCH 44/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20doc?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...blic.indexpatternsservice.createandsave.md | 2 +- ...lugins-data-public.indexpatternsservice.md | 2 +- ...na-plugin-plugins-data-public.searchbar.md | 4 ++-- ...-server.indexpatternsservice.__private_.md | 11 +++++++++ ...ternsservice.createindexpatternsservice.md | 23 +++++++++++++++++++ ...lugins-data-server.indexpatternsservice.md | 7 ++++++ ...-data-server.indexpatternsservice.start.md | 4 ++-- src/plugins/data/public/public.api.md | 4 ++-- src/plugins/data/server/server.api.md | 10 +++++--- 9 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md index eebfbb506fb77..a4036b2863f02 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md @@ -4,7 +4,7 @@ ## IndexPatternsService.createAndSave() method -Create a new index pattern and save it right away +Create a new index pattern and save it right away and make the default index pattern. Signature: diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md index 48019fe410b97..a472d721efad3 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md @@ -40,7 +40,7 @@ export declare class IndexPatternsService | Method | Modifiers | Description | | --- | --- | --- | | [create(spec, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.create.md) | | Create a new index pattern instance | -| [createAndSave(spec, override, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md) | | Create a new index pattern and save it right away | +| [createAndSave(spec, override, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md) | | Create a new index pattern and save it right away and make the default index pattern. | | [createSavedObject(indexPattern, override)](./kibana-plugin-plugins-data-public.indexpatternsservice.createsavedobject.md) | | Save a new index pattern | | [delete(indexPatternId)](./kibana-plugin-plugins-data-public.indexpatternsservice.delete.md) | | Deletes an index pattern from .kibana index | | [updateSavedObject(indexPattern, saveAttempts, ignoreErrors)](./kibana-plugin-plugins-data-public.indexpatternsservice.updatesavedobject.md) | | Save existing index pattern. Will attempt to merge differences if there are conflicts | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md index b886aafcfc00f..ee2ce6a2c9a76 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md @@ -7,7 +7,7 @@ Signature: ```typescript -SearchBar: React.ComponentClass, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { - WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; +SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "dataTestSubj" | "screenTitle" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { + WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; } ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md new file mode 100644 index 0000000000000..c909f5f961e1a --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) > ["\#private"](./kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md) + +## IndexPatternsService."\#private" property + +Signature: + +```typescript +#private; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md new file mode 100644 index 0000000000000..a1848adb75913 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) > [createIndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md) + +## IndexPatternsService.createIndexPatternsService() method + +Signature: + +```typescript +createIndexPatternsService(savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| savedObjectsClient | SavedObjectsClientContract | | +| elasticsearchClient | ElasticsearchClient | | + +Returns: + +`Promise` + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md index aa78c055f4f5c..d819f375e1f43 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md @@ -10,10 +10,17 @@ export declare class IndexPatternsService implements Plugin ``` +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| ["\#private"](./kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md) | | | | + ## Methods | Method | Modifiers | Description | | --- | --- | --- | +| [createIndexPatternsService(savedObjectsClient, elasticsearchClient)](./kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md) | | | | [setup(core)](./kibana-plugin-plugins-data-server.indexpatternsservice.setup.md) | | | | [start(core, { fieldFormats, logger })](./kibana-plugin-plugins-data-server.indexpatternsservice.start.md) | | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md index 6528b1c213cca..7a35fcb38b0f8 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md @@ -8,7 +8,7 @@ ```typescript start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): { - indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: Pick, elasticsearchClient: ElasticsearchClient) => Promise; }; ``` @@ -22,6 +22,6 @@ start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): Returns: `{ - indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: Pick, elasticsearchClient: ElasticsearchClient) => Promise; }` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index fc9b8d4839ea3..91f6fe7e18f7b 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -2035,8 +2035,8 @@ export const search: { // Warning: (ae-missing-release-tag) "SearchBar" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const SearchBar: React.ComponentClass, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "indexPatterns" | "dataTestSubj" | "screenTitle" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { - WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; +export const SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "dataTestSubj" | "screenTitle" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { + WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; }; // Warning: (ae-forgotten-export) The symbol "SearchBarOwnProps" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 47e17c26398d3..3e61d86801bea 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -738,13 +738,17 @@ export class IndexPatternsFetcher { // // @public (undocumented) export class IndexPatternsService implements Plugin_3 { + // (undocumented) + #private; + // (undocumented) + createIndexPatternsService(savedObjectsClient: SavedObjectsClientContract_2, elasticsearchClient: ElasticsearchClient_2): Promise; // (undocumented) setup(core: CoreSetup_2): void; // Warning: (ae-forgotten-export) The symbol "IndexPatternsServiceStartDeps" needs to be exported by the entry point index.d.ts // // (undocumented) start(core: CoreStart_2, { fieldFormats, logger }: IndexPatternsServiceStartDeps): { - indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract_2, elasticsearchClient: ElasticsearchClient_2) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: Pick, elasticsearchClient: ElasticsearchClient_2) => Promise; }; } @@ -1251,8 +1255,8 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:280:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:284:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:287:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index_patterns/index_patterns_service.ts:58:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/plugin.ts:88:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index_patterns/index_patterns_service.ts:62:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/plugin.ts:89:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From b8d140fc03e5ba9198c977e894ea656c14517f01 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 16:02:10 +0100 Subject: [PATCH 45/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20index=20patt?= =?UTF-8?q?er=20api=20get=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get_index_pattern/errors.ts | 44 +++++++++++++++++++ .../get_index_pattern/index.ts | 27 ++++++++++++ .../get_index_pattern/main.ts | 41 +++++++++++++++++ .../index_pattern_crud/index.ts | 1 + 4 files changed, 113 insertions(+) create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/index.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/main.ts diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts new file mode 100644 index 0000000000000..f2063f634ee2f --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts @@ -0,0 +1,44 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('returns 404 error on non-existing index_pattern', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest.get(`/api/index_patterns/index_pattern/${id}`); + + expect(response.status).to.be(404); + }); + + it('returns error when ID is too long', async () => { + const id = `xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx`; + const response = await supertest.get(`/api/index_patterns/index_pattern/${id}`); + + expect(response.status).to.be(400); + expect(response.body.message).to.be( + '[request params.id]: value has length [1759] but it must have a maximum length of [1000].' + ); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/index.ts new file mode 100644 index 0000000000000..74334cace2f2b --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('get_index_pattern', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/main.ts new file mode 100644 index 0000000000000..89a3e41258b0b --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/main.ts @@ -0,0 +1,41 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can retrieve an index_pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const response2 = await supertest.get( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(response2.body.index_pattern.title).to.be(title); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts index 8dde4eff20b68..b6882421126f4 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts @@ -22,5 +22,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ loadTestFile }: FtrProviderContext) { describe('index_pattern_crud', () => { loadTestFile(require.resolve('./create_index_pattern')); + loadTestFile(require.resolve('./get_index_pattern')); }); } From bf5b366320c3630f9eced2adafc68158ac9328d3 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 16:07:13 +0100 Subject: [PATCH 46/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20delete=20ind?= =?UTF-8?q?ex=20pattern=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../delete_index_pattern/errors.ts | 44 ++++++++++++ .../delete_index_pattern/index.ts | 27 ++++++++ .../delete_index_pattern/main.ts | 68 +++++++++++++++++++ .../get_index_pattern/errors.ts | 2 +- .../index_pattern_crud/index.ts | 1 + 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/errors.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/index.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/main.ts diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/errors.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/errors.ts new file mode 100644 index 0000000000000..b7b4bf8912682 --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/errors.ts @@ -0,0 +1,44 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns 404 error on non-existing index_pattern', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest.delete(`/api/index_patterns/index_pattern/${id}`); + + expect(response.status).to.be(404); + }); + + it('returns error when ID is too long', async () => { + const id = `xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx`; + const response = await supertest.delete(`/api/index_patterns/index_pattern/${id}`); + + expect(response.status).to.be(400); + expect(response.body.message).to.be( + '[request params.id]: value has length [1759] but it must have a maximum length of [1000].' + ); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/index.ts new file mode 100644 index 0000000000000..67a69812db8f9 --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('delete_index_pattern', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/main.ts new file mode 100644 index 0000000000000..bbf51779b6956 --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/delete_index_pattern/main.ts @@ -0,0 +1,68 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('deletes an index_pattern', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const response2 = await supertest.get( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(response2.status).to.be(200); + + const response3 = await supertest.delete( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(response3.status).to.be(200); + + const response4 = await supertest.get( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(response4.status).to.be(404); + }); + + it('returns nothing', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + await supertest.get('/api/index_patterns/index_pattern/' + response1.body.index_pattern.id); + const response2 = await supertest.delete( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(!!response2.body).to.be(false); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts index f2063f634ee2f..bf94d6b6b9444 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/get_index_pattern/errors.ts @@ -23,7 +23,7 @@ import { FtrProviderContext } from '../../../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - describe('main', () => { + describe('errors', () => { it('returns 404 error on non-existing index_pattern', async () => { const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; const response = await supertest.get(`/api/index_patterns/index_pattern/${id}`); diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts index b6882421126f4..0d357308c5a14 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts @@ -23,5 +23,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { describe('index_pattern_crud', () => { loadTestFile(require.resolve('./create_index_pattern')); loadTestFile(require.resolve('./get_index_pattern')); + loadTestFile(require.resolve('./delete_index_pattern')); }); } From 19974ee42e14e291eb8d6cf69af6d67902d8b7f5 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 23 Nov 2020 16:10:56 +0100 Subject: [PATCH 47/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20TypeScript=20?= =?UTF-8?q?error=20after=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/index_patterns/index_patterns/index_patterns.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts index 2cf840b8724b6..56576475de34d 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts @@ -209,7 +209,7 @@ describe('IndexPatterns', () => { const title = 'kibana-*'; indexPatterns.createSavedObject = jest.fn(); indexPatterns.setDefault = jest.fn(); - await indexPatterns.createAndSave({ title }, false, false, false); + await indexPatterns.createAndSave({ title }, false, false); expect(indexPatterns.createSavedObject).toBeCalled(); expect(indexPatterns.setDefault).not.toBeCalled(); }); From 1cef682d67a44a622363742e16584dcf3753551b Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 26 Nov 2020 12:56:28 +0100 Subject: [PATCH 48/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20aut?= =?UTF-8?q?ogenerated=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...na-plugin-plugins-data-public.searchbar.md | 4 +- src/plugins/data/public/public.api.md | 6 +- src/plugins/data/server/server.api.md | 70 +++++++++---------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md index ee2ce6a2c9a76..0718ca38febbd 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md @@ -7,7 +7,7 @@ Signature: ```typescript -SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "dataTestSubj" | "screenTitle" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { - WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; +SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "dataTestSubj" | "refreshInterval" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { + WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; } ``` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 95229a67708e3..eb276bc65b5bb 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -2047,8 +2047,8 @@ export const search: { // Warning: (ae-missing-release-tag) "SearchBar" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "dataTestSubj" | "screenTitle" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { - WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; +export const SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "dataTestSubj" | "refreshInterval" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { + WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; }; // Warning: (ae-forgotten-export) The symbol "SearchBarOwnProps" needs to be exported by the entry point index.d.ts @@ -2375,7 +2375,7 @@ export const UI_SETTINGS: { // src/plugins/data/common/es_query/filters/phrase_filter.ts:33:3 - (ae-forgotten-export) The symbol "PhraseFilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/es_query/filters/phrases_filter.ts:31:3 - (ae-forgotten-export) The symbol "PhrasesFilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:64:5 - (ae-forgotten-export) The symbol "FormatFieldFn" needs to be exported by the entry point index.d.ts -// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:135:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:136:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts // src/plugins/data/common/search/aggs/types.ts:113:51 - (ae-forgotten-export) The symbol "AggTypesRegistryStart" needs to be exported by the entry point index.d.ts // src/plugins/data/public/field_formats/field_formats_service.ts:67:3 - (ae-forgotten-export) The symbol "FormatFactory" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:66:23 - (ae-forgotten-export) The symbol "FILTERS" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 3d9ca7e0033c2..0bd804689913c 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -1216,43 +1216,43 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/common/es_query/filters/meta_filter.ts:54:3 - (ae-forgotten-export) The symbol "FilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:58:45 - (ae-forgotten-export) The symbol "IndexPatternFieldMap" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:64:5 - (ae-forgotten-export) The symbol "FormatFieldFn" needs to be exported by the entry point index.d.ts -// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:135:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:136:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildCustomFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "buildEsQuery" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:258:5 - (ae-forgotten-export) The symbol "getTotalLoaded" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:259:5 - (ae-forgotten-export) The symbol "toSnakeCase" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:263:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:264:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:273:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:279:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:280:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:284:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:287:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:57:23 - (ae-forgotten-export) The symbol "datatableToCSV" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:81:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:81:21 - (ae-forgotten-export) The symbol "buildEsQuery" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:111:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:137:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:137:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:248:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:248:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:248:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:248:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:250:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:251:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:260:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:261:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:262:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:266:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:267:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:271:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index_patterns/index_patterns_service.ts:62:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts // src/plugins/data/server/plugin.ts:89:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts From c1d9963b40eddb8f1ab5f6df44e9b9360173d21e Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 26 Nov 2020 13:14:26 +0100 Subject: [PATCH 49/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20aut?= =?UTF-8?q?ogenerated=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/server/server.api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index b7297a17b7b64..bf4dec2573ebb 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -1255,7 +1255,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index_patterns/index_patterns_service.ts:62:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/plugin.ts:89:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/plugin.ts:91:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From a82a21e5cfe182354ad22626aade19e2896bc077 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 12:15:45 +0100 Subject: [PATCH 50/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20change=20Field?= =?UTF-8?q?s=20API=20to=20Scripted=20Fields=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes.ts | 20 +++++++++---------- .../create_scripted_field.ts} | 4 ++-- .../delete_scripted_field.ts} | 4 ++-- .../get_scripted_field.ts} | 4 ++-- .../put_scripted_field.ts} | 4 ++-- .../update_scripted_field.ts} | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) rename src/plugins/data/server/index_patterns/routes/{fields/create_field.ts => scripted_fields/create_scripted_field.ts} (95%) rename src/plugins/data/server/index_patterns/routes/{fields/delete_field.ts => scripted_fields/delete_scripted_field.ts} (94%) rename src/plugins/data/server/index_patterns/routes/{fields/get_field.ts => scripted_fields/get_scripted_field.ts} (93%) rename src/plugins/data/server/index_patterns/routes/{fields/put_field.ts => scripted_fields/put_scripted_field.ts} (95%) rename src/plugins/data/server/index_patterns/routes/{fields/update_field.ts => scripted_fields/update_scripted_field.ts} (96%) diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index d53465be16aba..69fd08e3261fa 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -24,11 +24,11 @@ import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; import { registerDeleteIndexPatternRoute } from './routes/delete_index_pattern'; import { registerUpdateIndexPatternRoute } from './routes/update_index_pattern'; -import { registerCreateFieldRoute } from './routes/fields/create_field'; -import { registerPutFieldRoute } from './routes/fields/put_field'; -import { registerGetFieldRoute } from './routes/fields/get_field'; -import { registerDeleteFieldRoute } from './routes/fields/delete_field'; -import { registerUpdateFieldRoute } from './routes/fields/update_field'; +import { registerCreateScriptedFieldRoute } from './routes/scripted_fields/create_scripted_field'; +import { registerPutScriptedFieldRoute } from './routes/scripted_fields/put_scripted_field'; +import { registerGetScriptedFieldRoute } from './routes/scripted_fields/get_scripted_field'; +import { registerDeleteScriptedFieldRoute } from './routes/scripted_fields/delete_scripted_field'; +import { registerUpdateScriptedFieldRoute } from './routes/scripted_fields/update_scripted_field'; export function registerRoutes(http: HttpServiceSetup) { const parseMetaFields = (metaFields: string | string[]) => { @@ -47,11 +47,11 @@ export function registerRoutes(http: HttpServiceSetup) { registerGetIndexPatternRoute(router); registerDeleteIndexPatternRoute(router); registerUpdateIndexPatternRoute(router); - registerCreateFieldRoute(router); - registerPutFieldRoute(router); - registerGetFieldRoute(router); - registerDeleteFieldRoute(router); - registerUpdateFieldRoute(router); + registerCreateScriptedFieldRoute(router); + registerPutScriptedFieldRoute(router); + registerGetScriptedFieldRoute(router); + registerDeleteScriptedFieldRoute(router); + registerUpdateScriptedFieldRoute(router); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts similarity index 95% rename from src/plugins/data/server/index_patterns/routes/fields/create_field.ts rename to src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 9af476e792c63..381cbde77bac6 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/create_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -23,10 +23,10 @@ import { assertIndexPatternsContext } from '../util/assert_index_patterns_contex import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; -export const registerCreateFieldRoute = (router: IRouter) => { +export const registerCreateScriptedFieldRoute = (router: IRouter) => { router.post( { - path: '/api/index_patterns/index_pattern/{id}/field', + path: '/api/index_patterns/index_pattern/{id}/scripted_field', validate: { params: schema.object( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts similarity index 94% rename from src/plugins/data/server/index_patterns/routes/fields/delete_field.ts rename to src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts index a893c444f092c..4ae0e7a10c68f 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/delete_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts @@ -23,10 +23,10 @@ import { ErrorIndexPatternFieldNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; -export const registerDeleteFieldRoute = (router: IRouter) => { +export const registerDeleteScriptedFieldRoute = (router: IRouter) => { router.delete( { - path: '/api/index_patterns/index_pattern/{id}/field/{name}', + path: '/api/index_patterns/index_pattern/{id}/scripted_field/{name}', validate: { params: schema.object( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts similarity index 93% rename from src/plugins/data/server/index_patterns/routes/fields/get_field.ts rename to src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts index 841fd6829bc04..e691b80c8043c 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/get_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts @@ -23,10 +23,10 @@ import { ErrorIndexPatternFieldNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; -export const registerGetFieldRoute = (router: IRouter) => { +export const registerGetScriptedFieldRoute = (router: IRouter) => { router.get( { - path: '/api/index_patterns/index_pattern/{id}/field/{name}', + path: '/api/index_patterns/index_pattern/{id}/scripted_field/{name}', validate: { params: schema.object( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/put_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts similarity index 95% rename from src/plugins/data/server/index_patterns/routes/fields/put_field.ts rename to src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index eefa3681372b1..d73081b118ed1 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/put_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -23,10 +23,10 @@ import { assertIndexPatternsContext } from '../util/assert_index_patterns_contex import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; -export const registerPutFieldRoute = (router: IRouter) => { +export const registerPutScriptedFieldRoute = (router: IRouter) => { router.put( { - path: '/api/index_patterns/index_pattern/{id}/field', + path: '/api/index_patterns/index_pattern/{id}/scripted_field', validate: { params: schema.object( { diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts similarity index 96% rename from src/plugins/data/server/index_patterns/routes/fields/update_field.ts rename to src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index 2a1d01e98ec58..57635923990d4 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -25,10 +25,10 @@ import { assertIndexPatternsContext } from '../util/assert_index_patterns_contex import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchemaFields } from '../util/schemas'; -export const registerUpdateFieldRoute = (router: IRouter) => { +export const registerUpdateScriptedFieldRoute = (router: IRouter) => { router.post( { - path: '/api/index_patterns/index_pattern/{id}/field/{name}', + path: '/api/index_patterns/index_pattern/{id}/scripted_field/{name}', validate: { params: schema.object( { From 8254ca98da065040c988d800cc6697e42822f631 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 12:18:45 +0100 Subject: [PATCH 51/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20allow=20only=20scr?= =?UTF-8?q?ipted=20fields=20in=20Scripted=20Fields=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/scripted_fields/get_scripted_field.ts | 4 ++++ .../routes/scripted_fields/put_scripted_field.ts | 4 ++++ .../routes/scripted_fields/update_scripted_field.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts index e691b80c8043c..3ca772af001d4 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts @@ -57,6 +57,10 @@ export const registerGetScriptedFieldRoute = (router: IRouter) => { throw new ErrorIndexPatternFieldNotFound(id, name); } + if (!field.scripted) { + throw new Error('Only scripted fields can be retrieved.'); + } + return res.ok({ headers: { 'content-type': 'application/json', diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index d73081b118ed1..b85377be398fb 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -54,6 +54,10 @@ export const registerPutScriptedFieldRoute = (router: IRouter) => { field, } = req.body; + if (!field.scripted) { + throw new Error('Only scripted fields can be put.'); + } + const indexPattern = await ip.get(id); const oldFieldObject = indexPattern.fields.getByName(field.name); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index 57635923990d4..7c3ef05f5e159 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -77,6 +77,10 @@ export const registerUpdateScriptedFieldRoute = (router: IRouter) => { const field = ({ ...req.body.field, name } as unknown) as FieldSpec; + if (!field.scripted) { + throw new Error('Only scripted fields can be updated.'); + } + const indexPattern = await ip.get(id); let fieldObject = indexPattern.fields.getByName(field.name); From d1fcb11831d7b84b1eb4a94e186421ea0e4802e8 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 13:49:16 +0100 Subject: [PATCH 52/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20index=20patt?= =?UTF-8?q?er=20api=20update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_pattern_crud/index.ts | 1 + .../update_index_pattern/errors.ts | 83 +++++ .../update_index_pattern/index.ts | 27 ++ .../update_index_pattern/main.ts | 349 ++++++++++++++++++ 4 files changed, 460 insertions(+) create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/errors.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/index.ts create mode 100644 test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts index 0d357308c5a14..7445ea81f9939 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/index.ts @@ -24,5 +24,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./create_index_pattern')); loadTestFile(require.resolve('./get_index_pattern')); loadTestFile(require.resolve('./delete_index_pattern')); + loadTestFile(require.resolve('./update_index_pattern')); }); } diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/errors.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/errors.ts new file mode 100644 index 0000000000000..f1e8ac9ea7f76 --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/errors.ts @@ -0,0 +1,83 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns error when index_pattern object is not provided', async () => { + const response = await supertest.post('/api/index_patterns/index_pattern/foo'); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + '[request body]: expected a plain object value, but found [null] instead.' + ); + }); + + it('returns error on non-existing index_pattern', async () => { + const response = await supertest + .post('/api/index_patterns/index_pattern/non-existing-index-pattern') + .send({ + index_pattern: {}, + }); + + expect(response.status).to.be(404); + expect(response.body.statusCode).to.be(404); + expect(response.body.message).to.be( + 'Saved object [index-pattern/non-existing-index-pattern] not found' + ); + }); + + it('returns error when "refresh_fields" parameter is not a boolean', async () => { + const response = await supertest.post('/api/index_patterns/index_pattern/foo`').send({ + refresh_fields: 123, + index_pattern: { + title: 'foo', + }, + }); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + '[request body.refresh_fields]: expected value of type [boolean] but got [number]' + ); + }); + + it('returns error when update patch is empty', async () => { + const title1 = `foo-${Date.now()}-${Math.random()}*`; + const response = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title: title1, + }, + }); + const id = response.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: {}, + }); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be('Index pattern change set is empty.'); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/index.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/index.ts new file mode 100644 index 0000000000000..d4d98f2bc637a --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('update_index_pattern', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts new file mode 100644 index 0000000000000..304f9ce66e799 --- /dev/null +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts @@ -0,0 +1,349 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can update index_pattern title', async () => { + const title1 = `foo-${Date.now()}-${Math.random()}*`; + const title2 = `bar-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title: title1, + }, + }); + + expect(response1.body.index_pattern.title).to.be(title1); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + title: title2, + }, + }); + + expect(response2.body.index_pattern.title).to.be(title2); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.title).to.be(title2); + }); + + it('can update index_pattern timeFieldName', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + timeFieldName: 'timeFieldName1', + }, + }); + + expect(response1.body.index_pattern.timeFieldName).to.be('timeFieldName1'); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + timeFieldName: 'timeFieldName2', + }, + }); + + expect(response2.body.index_pattern.timeFieldName).to.be('timeFieldName2'); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.timeFieldName).to.be('timeFieldName2'); + }); + + it('can update index_pattern intervalName', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + intervalName: 'intervalName1', + }, + }); + + expect(response1.body.index_pattern.intervalName).to.be('intervalName1'); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + intervalName: 'intervalName2', + }, + }); + + expect(response2.body.index_pattern.intervalName).to.be('intervalName2'); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.intervalName).to.be('intervalName2'); + }); + + it('can update index_pattern sourceFilters', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + sourceFilters: [ + { + value: 'foo', + }, + ], + }, + }); + + expect(response1.body.index_pattern.sourceFilters).to.eql([ + { + value: 'foo', + }, + ]); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + sourceFilters: [ + { + value: 'bar', + }, + { + value: 'baz', + }, + ], + }, + }); + + expect(response2.body.index_pattern.sourceFilters).to.eql([ + { + value: 'bar', + }, + { + value: 'baz', + }, + ]); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.sourceFilters).to.eql([ + { + value: 'bar', + }, + { + value: 'baz', + }, + ]); + }); + + it('can update index_pattern fieldFormats', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldFormats: { + foo: { + id: 'foo', + params: { + bar: 'baz', + }, + }, + }, + }, + }); + + expect(response1.body.index_pattern.fieldFormats).to.eql({ + foo: { + id: 'foo', + params: { + bar: 'baz', + }, + }, + }); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + fieldFormats: { + a: { + id: 'a', + params: { + b: 'v', + }, + }, + }, + }, + }); + + expect(response2.body.index_pattern.fieldFormats).to.eql({ + a: { + id: 'a', + params: { + b: 'v', + }, + }, + }); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.fieldFormats).to.eql({ + a: { + id: 'a', + params: { + b: 'v', + }, + }, + }); + }); + + it('can update index_pattern type', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + type: 'foo', + }, + }); + + expect(response1.body.index_pattern.type).to.be('foo'); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + type: 'bar', + }, + }); + + expect(response2.body.index_pattern.type).to.be('bar'); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.type).to.be('bar'); + }); + + it('can update index_pattern typeMeta', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + typeMeta: { foo: 'bar' }, + }, + }); + + expect(response1.body.index_pattern.typeMeta).to.eql({ foo: 'bar' }); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + typeMeta: { foo: 'baz' }, + }, + }); + + expect(response2.body.index_pattern.typeMeta).to.eql({ foo: 'baz' }); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.typeMeta).to.eql({ foo: 'baz' }); + }); + + it('can update index_pattern fields', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + searchable: false, + aggregatable: false, + }, + }, + }, + }); + + expect(response1.body.index_pattern.fields.foo.name).to.be('foo'); + expect(response1.body.index_pattern.fields.foo.type).to.be('string'); + expect(response1.body.index_pattern.fields.foo.searchable).to.be(false); + expect(response1.body.index_pattern.fields.foo.aggregatable).to.be(false); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + fields: { + bar: { + name: 'bar', + type: 'number', + searchable: true, + aggregatable: true, + }, + }, + }, + }); + + expect(response2.body.index_pattern.fields.bar.name).to.be('bar'); + expect(response2.body.index_pattern.fields.bar.type).to.be('number'); + expect(response2.body.index_pattern.fields.bar.searchable).to.be(true); + expect(response2.body.index_pattern.fields.bar.aggregatable).to.be(true); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.fields.bar.name).to.be('bar'); + expect(response3.body.index_pattern.fields.bar.type).to.be('number'); + expect(response3.body.index_pattern.fields.bar.searchable).to.be(true); + expect(response3.body.index_pattern.fields.bar.aggregatable).to.be(true); + }); + + it('can multiple index pattern fields at once', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + timeFieldName: 'timeFieldName1', + intervalName: 'intervalName1', + typeMeta: { foo: 'bar' }, + }, + }); + + expect(response1.body.index_pattern.timeFieldName).to.be('timeFieldName1'); + expect(response1.body.index_pattern.intervalName).to.be('intervalName1'); + expect(response1.body.index_pattern.typeMeta.foo).to.be('bar'); + + const id = response1.body.index_pattern.id; + const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ + index_pattern: { + timeFieldName: 'timeFieldName2', + intervalName: 'intervalName2', + typeMeta: { baz: 'qux' }, + }, + }); + + expect(response2.body.index_pattern.timeFieldName).to.be('timeFieldName2'); + expect(response2.body.index_pattern.intervalName).to.be('intervalName2'); + expect(response2.body.index_pattern.typeMeta.baz).to.be('qux'); + + const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); + + expect(response3.body.index_pattern.timeFieldName).to.be('timeFieldName2'); + expect(response3.body.index_pattern.intervalName).to.be('intervalName2'); + expect(response3.body.index_pattern.typeMeta.baz).to.be('qux'); + }); + }); +} From 92160a5b8423cf3910c185a860585ff43268394b Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 14:36:41 +0100 Subject: [PATCH 53/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20scripted=20f?= =?UTF-8?q?ield=20create=20api=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/index_patterns/index.js | 1 + .../create_scripted_field/errors.ts | 99 +++++++++++++++++++ .../create_scripted_field/index.ts | 27 +++++ .../create_scripted_field/main.ts | 94 ++++++++++++++++++ .../scripted_fields_crud/index.ts | 26 +++++ 5 files changed, 247 insertions(+) create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/index.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts diff --git a/test/api_integration/apis/index_patterns/index.js b/test/api_integration/apis/index_patterns/index.js index 7208c8c655bfb..c7ed1f240a6ea 100644 --- a/test/api_integration/apis/index_patterns/index.js +++ b/test/api_integration/apis/index_patterns/index.js @@ -23,5 +23,6 @@ export default function ({ loadTestFile }) { loadTestFile(require.resolve('./fields_for_time_pattern_route')); loadTestFile(require.resolve('./fields_for_wildcard_route')); loadTestFile(require.resolve('./index_pattern_crud')); + loadTestFile(require.resolve('./scripted_fields_crud')); }); } diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts new file mode 100644 index 0000000000000..d0f7b7feaae91 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts @@ -0,0 +1,99 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns an error field object is not provided', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const id = response1.body.index_pattern.id; + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${id}/scripted_field`) + .send({}); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be( + '[request body.field.name]: expected value of type [string] but got [undefined]' + ); + }); + + it('returns an error field object is not provided', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const id = response1.body.index_pattern.id; + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${id}/scripted_field`) + .send({ + refresh_fields: 123, + field: { + name: 'bar', + type: 'number', + scripted: false, + searchable: true, + aggregatable: true, + }, + }); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be( + '[request body.refresh_fields]: expected value of type [boolean] but got [number]' + ); + }); + + it('returns an error when creating a non-scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const id = response1.body.index_pattern.id; + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${id}/scripted_field`) + .send({ + field: { + name: 'bar', + type: 'number', + scripted: false, + searchable: true, + aggregatable: true, + }, + }); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be('Only scripted fields can be created.'); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/index.ts new file mode 100644 index 0000000000000..b7e886f38f8a7 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('create_scripted_field', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts new file mode 100644 index 0000000000000..34b48ec1fb431 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts @@ -0,0 +1,94 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can create a new scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const id = response1.body.index_pattern.id; + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${id}/scripted_field`) + .send({ + field: { + name: 'bar', + type: 'number', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.field.name).to.be('bar'); + expect(response2.body.field.type).to.be('number'); + expect(response2.body.field.scripted).to.be(true); + expect(response2.body.field.script).to.be("doc['field_name'].value"); + expect(response2.body.field.searchable).to.be(true); + expect(response2.body.field.aggregatable).to.be(true); + }); + + it('newly created scripted field is materialized in the index_pattern object', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field`) + .send({ + field: { + name: 'bar', + type: 'number', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }); + + const response2 = await supertest.get( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(response2.status).to.be(200); + + const field = response2.body.index_pattern.fields.bar; + + expect(field.name).to.be('bar'); + expect(field.type).to.be('number'); + expect(field.scripted).to.be(true); + expect(field.script).to.be("doc['field_name'].value"); + expect(field.searchable).to.be(true); + expect(field.aggregatable).to.be(true); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts new file mode 100644 index 0000000000000..f4fd48ba66db2 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('scripted_fields_crud', () => { + loadTestFile(require.resolve('./create_scripted_field')); + }); +} From f83b52d623e2d37a103cb737c6a2273d6b7bbd39 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 14:50:48 +0100 Subject: [PATCH 54/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20scripted=20f?= =?UTF-8?q?ield=20delete=20api=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../delete_scripted_field/errors.ts | 87 +++++++++++++++++++ .../delete_scripted_field/index.ts | 27 ++++++ .../delete_scripted_field/main.ts | 64 ++++++++++++++ .../scripted_fields_crud/index.ts | 1 + 4 files changed, 179 insertions(+) create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/index.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts new file mode 100644 index 0000000000000..48527cc37e9af --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns 404 error on non-existing index_pattern', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest.delete( + `/api/index_patterns/index_pattern/${id}/scripted_field/foo` + ); + + expect(response.status).to.be(404); + }); + + it('returns 404 error on non-existing scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const response2 = await supertest.delete( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + ); + + expect(response2.status).to.be(404); + }); + + it('returns error when attempting to delete a field which is not a scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + scripted: false, + name: 'foo', + type: 'string', + searchable: false, + aggregatable: false, + }, + }, + }, + }); + const response2 = await supertest.delete( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + ); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be('Only scripted fields can be deleted.'); + }); + + it('returns error when ID is too long', async () => { + const id = `xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx`; + const response = await supertest.delete( + `/api/index_patterns/index_pattern/${id}/scripted_field/foo` + ); + + expect(response.status).to.be(400); + expect(response.body.message).to.be( + '[request params.id]: value has length [1759] but it must have a maximum length of [1000].' + ); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/index.ts new file mode 100644 index 0000000000000..717d4d5627295 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('delete_scripted_field', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts new file mode 100644 index 0000000000000..c202646a30ace --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts @@ -0,0 +1,64 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can remove a scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + bar: { + name: 'bar', + type: 'number', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }, + }, + }); + + const response2 = await supertest.get( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(typeof response2.body.index_pattern.fields.bar).to.be('object'); + + const response3 = await supertest.delete( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/bar` + ); + + expect(response3.status).to.be(200); + + const response4 = await supertest.get( + '/api/index_patterns/index_pattern/' + response1.body.index_pattern.id + ); + + expect(typeof response4.body.index_pattern.fields.bar).to.be('undefined'); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts index f4fd48ba66db2..943d0b81bb1b5 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts @@ -22,5 +22,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ loadTestFile }: FtrProviderContext) { describe('scripted_fields_crud', () => { loadTestFile(require.resolve('./create_scripted_field')); + loadTestFile(require.resolve('./delete_scripted_field')); }); } From 8e50647b2c94d76e7992cd36c21984fcc293607d Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 15:16:50 +0100 Subject: [PATCH 55/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20scripted=20f?= =?UTF-8?q?ields=20fetch=20api=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get_scripted_field/errors.ts | 87 +++++++++++++++++++ .../get_scripted_field/index.ts | 27 ++++++ .../get_scripted_field/main.ts | 67 ++++++++++++++ .../scripted_fields_crud/index.ts | 1 + 4 files changed, 182 insertions(+) create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/index.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts new file mode 100644 index 0000000000000..665ba94ec29d2 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns 404 error on non-existing index_pattern', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest.get( + `/api/index_patterns/index_pattern/${id}/scripted_field/foo` + ); + + expect(response.status).to.be(404); + }); + + it('returns 404 error on non-existing scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const response2 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + ); + + expect(response2.status).to.be(404); + }); + + it('returns error when attempting to fetch a field which is not a scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + scripted: false, + name: 'foo', + type: 'string', + searchable: false, + aggregatable: false, + }, + }, + }, + }); + const response2 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + ); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be('Only scripted fields can be retrieved.'); + }); + + it('returns error when ID is too long', async () => { + const id = `xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx`; + const response = await supertest.get( + `/api/index_patterns/index_pattern/${id}/scripted_field/foo` + ); + + expect(response.status).to.be(400); + expect(response.body.message).to.be( + '[request params.id]: value has length [1759] but it must have a maximum length of [1000].' + ); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/index.ts new file mode 100644 index 0000000000000..f102a379c1c80 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('get_scripted_field', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts new file mode 100644 index 0000000000000..eb2019b0e98b8 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts @@ -0,0 +1,67 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can fetch a scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + bar: { + name: 'bar', + type: 'number', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }, + }, + }); + + const response2 = await supertest.get( + '/api/index_patterns/index_pattern/' + + response1.body.index_pattern.id + + '/scripted_field/bar' + ); + + expect(response2.status).to.be(200); + expect(typeof response2.body.field).to.be('object'); + expect(response2.body.field.name).to.be('bar'); + expect(response2.body.field.type).to.be('number'); + expect(response2.body.field.scripted).to.be(true); + expect(response2.body.field.script).to.be("doc['field_name'].value"); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts index 943d0b81bb1b5..e642da1ea7c6e 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts @@ -22,6 +22,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ loadTestFile }: FtrProviderContext) { describe('scripted_fields_crud', () => { loadTestFile(require.resolve('./create_scripted_field')); + loadTestFile(require.resolve('./get_scripted_field')); loadTestFile(require.resolve('./delete_scripted_field')); }); } From 7c4872b41c3988d1096451819d56b96df94ef07c Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 15:50:58 +0100 Subject: [PATCH 56/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20scripted=20f?= =?UTF-8?q?ield=20field=20put=20api=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../put_scripted_field/errors.ts | 91 +++++++++++++ .../put_scripted_field/index.ts | 27 ++++ .../put_scripted_field/main.ts | 126 ++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/index.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts new file mode 100644 index 0000000000000..e4dca1b15ab5f --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts @@ -0,0 +1,91 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns 404 error on non-existing index_pattern', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest + .put(`/api/index_patterns/index_pattern/${id}/scripted_field`) + .send({ + field: { + name: 'foo', + type: 'number', + scripted: true, + }, + }); + + expect(response.status).to.be(404); + }); + + it('returns error update fields which is not a scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + scripted: false, + name: 'foo', + type: 'string', + searchable: false, + aggregatable: false, + }, + }, + }, + }); + const response2 = await supertest + .put(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field`) + .send({ + field: { + name: 'foo', + type: 'number', + }, + }); + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be('Only scripted fields can be put.'); + }); + + it('returns error when ID is too long', async () => { + const id = `xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx`; + const response = await supertest + .put(`/api/index_patterns/index_pattern/${id}/scripted_field`) + .send({ + field: { + field: { + name: 'foo', + type: 'number', + scripted: true, + }, + }, + }); + + expect(response.status).to.be(400); + expect(response.body.message).to.be( + '[request params.id]: value has length [1759] but it must have a maximum length of [1000].' + ); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/index.ts new file mode 100644 index 0000000000000..8f45bfc15fe1f --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('put_scripted_field', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts new file mode 100644 index 0000000000000..ee410576c89fb --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts @@ -0,0 +1,126 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can overwrite an existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + bar: { + name: 'bar', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }, + }, + }); + + await supertest + .put(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field`) + .send({ + field: { + name: 'foo', + type: 'number', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }); + + const response2 = await supertest.get( + '/api/index_patterns/index_pattern/' + + response1.body.index_pattern.id + + '/scripted_field/foo' + ); + + expect(response2.status).to.be(200); + expect(response2.body.field.type).to.be('number'); + + const response3 = await supertest.get( + '/api/index_patterns/index_pattern/' + + response1.body.index_pattern.id + + '/scripted_field/bar' + ); + + expect(response3.status).to.be(200); + expect(response3.body.field.type).to.be('string'); + }); + + it('can add a new scripted field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }, + }, + }); + + await supertest + .put(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field`) + .send({ + field: { + name: 'bar', + type: 'number', + scripted: true, + script: "doc['bar'].value", + searchable: true, + aggregatable: true, + }, + }); + + const response2 = await supertest.get( + '/api/index_patterns/index_pattern/' + + response1.body.index_pattern.id + + '/scripted_field/bar' + ); + + expect(response2.status).to.be(200); + expect(response2.body.field.script).to.be("doc['bar'].value"); + }); + }); +} From 186007089364c2d6ab315463eec423b700b1ea4f Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 17:09:34 +0100 Subject: [PATCH 57/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20scripted=20f?= =?UTF-8?q?ield=20update=20api=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scripted_fields/update_scripted_field.ts | 8 +- .../scripted_fields_crud/index.ts | 2 + .../update_scripted_field/errors.ts | 79 +++++++++++++++++++ .../update_scripted_field/index.ts | 27 +++++++ .../update_scripted_field/main.ts | 76 ++++++++++++++++++ 5 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/errors.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/index.ts create mode 100644 test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index 7c3ef05f5e159..c5313cc3be51a 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -77,10 +77,6 @@ export const registerUpdateScriptedFieldRoute = (router: IRouter) => { const field = ({ ...req.body.field, name } as unknown) as FieldSpec; - if (!field.scripted) { - throw new Error('Only scripted fields can be updated.'); - } - const indexPattern = await ip.get(id); let fieldObject = indexPattern.fields.getByName(field.name); @@ -88,6 +84,10 @@ export const registerUpdateScriptedFieldRoute = (router: IRouter) => { throw new ErrorIndexPatternFieldNotFound(id, name); } + if (!fieldObject.scripted) { + throw new Error('Only scripted fields can be updated.'); + } + const oldSpec = fieldObject.toSpec(); indexPattern.fields.remove(fieldObject); diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts index e642da1ea7c6e..78332d68cac0c 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/index.ts @@ -24,5 +24,7 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./create_scripted_field')); loadTestFile(require.resolve('./get_scripted_field')); loadTestFile(require.resolve('./delete_scripted_field')); + loadTestFile(require.resolve('./put_scripted_field')); + loadTestFile(require.resolve('./update_scripted_field')); }); } diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/errors.ts new file mode 100644 index 0000000000000..ff0e9120bbe70 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/errors.ts @@ -0,0 +1,79 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns 404 error on non-existing index_pattern', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest + .post(`/api/index_patterns/index_pattern/${id}/scripted_field/foo`) + .send({ + field: { + type: 'number', + scripted: true, + }, + }); + + expect(response.status).to.be(404); + }); + + it('returns error when field name is specified', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest + .post(`/api/index_patterns/index_pattern/${id}/scripted_field/foo`) + .send({ + field: { + name: 'foo', + type: 'number', + scripted: true, + }, + }); + + expect(response.status).to.be(400); + expect(response.body.statusCode).to.be(400); + expect(response.body.message).to.be( + "[request body.field.name]: a value wasn't expected to be present" + ); + }); + + it('returns error when ID is too long', async () => { + const id = `xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx`; + const response = await supertest + .post(`/api/index_patterns/index_pattern/${id}/scripted_field/foo`) + .send({ + field: { + field: { + type: 'number', + scripted: true, + }, + }, + }); + + expect(response.status).to.be(400); + expect(response.body.message).to.be( + '[request params.id]: value has length [1759] but it must have a maximum length of [1000].' + ); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/index.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/index.ts new file mode 100644 index 0000000000000..fdc7d94322c66 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('update_scripted_field', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts new file mode 100644 index 0000000000000..502370cb32b04 --- /dev/null +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts @@ -0,0 +1,76 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can update an existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + bar: { + name: 'bar', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + searchable: true, + aggregatable: true, + }, + }, + }, + }); + + const response2 = await supertest + .post( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + ) + .send({ + field: { + script: "doc['bar'].value", + }, + }); + + expect(response2.body.field.script).to.be("doc['bar'].value"); + + const response3 = await supertest.get( + '/api/index_patterns/index_pattern/' + + response1.body.index_pattern.id + + '/scripted_field/foo' + ); + + expect(response3.status).to.be(200); + expect(response3.body.field.type).to.be('string'); + expect(response3.body.field.script).to.be("doc['bar'].value"); + }); + }); +} From 1f854905c303587efd2e258e670b6fe17325047e Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 17:58:27 +0100 Subject: [PATCH 58/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20index=20patt?= =?UTF-8?q?ern=20field=20update=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fields/index_pattern_field.ts | 2 +- .../index_patterns/index_pattern.ts | 51 +++++-- .../routes/fields/update_field.ts | 127 ++++++++++++++++++ 3 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 src/plugins/data/server/index_patterns/routes/fields/update_field.ts diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts index 4dd2d29f38e9f..e8a9d21ae1cc3 100644 --- a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts +++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts @@ -42,7 +42,7 @@ export class IndexPatternField implements IFieldType { return this.spec.count || 0; } - public set count(count) { + public set count(count: number | undefined) { this.spec.count = count; } diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 7ef457a866a39..6aeb4d601c6e0 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -112,14 +112,6 @@ export class IndexPattern implements IIndexPattern { this.intervalName = spec.intervalName; } - setFieldFormat = (fieldName: string, format: SerializedFieldFormat) => { - this.fieldFormatMap[fieldName] = format; - }; - - deleteFieldFormat = (fieldName: string) => { - delete this.fieldFormatMap[fieldName]; - }; - /** * Get last saved saved object fields */ @@ -348,4 +340,47 @@ export class IndexPattern implements IIndexPattern { return this.fieldFormats.getInstance(formatSpec.id, formatSpec.params); } } + + protected setFieldAttrs( + fieldName: string, + attrName: K, + value: FieldAttrSet[K] + ) { + if (!this.fieldAttrs[fieldName]) { + this.fieldAttrs[fieldName] = {} as FieldAttrSet; + } + this.fieldAttrs[fieldName][attrName] = value; + } + + public setFieldCustomLabel(fieldName: string, customLabel: string | undefined | null) { + const fieldObject = this.fields.getByName(fieldName); + const newCustomLabel: string | undefined = customLabel === null ? undefined : customLabel; + + if (fieldObject) { + fieldObject.customLabel = newCustomLabel; + return; + } + + this.setFieldAttrs(fieldName, 'customLabel', newCustomLabel); + } + + public setFieldCount(fieldName: string, count: number | undefined | null) { + const fieldObject = this.fields.getByName(fieldName); + const newCount: number | undefined = count === null ? undefined : count; + + if (fieldObject) { + fieldObject.count = newCount; + return; + } + + this.setFieldAttrs(fieldName, 'count', newCount); + } + + public readonly setFieldFormat = (fieldName: string, format: SerializedFieldFormat) => { + this.fieldFormatMap[fieldName] = format; + }; + + public readonly deleteFieldFormat = (fieldName: string) => { + delete this.fieldFormatMap[fieldName]; + }; } diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts b/src/plugins/data/server/index_patterns/routes/fields/update_field.ts new file mode 100644 index 0000000000000..0ec1920ec7909 --- /dev/null +++ b/src/plugins/data/server/index_patterns/routes/fields/update_field.ts @@ -0,0 +1,127 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { IRouter } from '../../../../../../core/server'; +import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; +import { handleErrors } from '../util/handle_errors'; +import { serializedFieldFormatSchema } from '../util/schemas'; + +export const registerUpdateScriptedFieldRoute = (router: IRouter) => { + router.post( + { + path: '/api/index_patterns/index_pattern/{id}/fields', + validate: { + params: schema.object( + { + id: schema.string({ + minLength: 1, + maxLength: 1_000, + }), + }, + { unknowns: 'allow' } + ), + body: schema.object({ + refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), + fields: schema.recordOf( + schema.string({ + minLength: 1, + maxLength: 1_000, + }), + schema.object({ + customLabel: schema.maybe( + schema.nullable( + schema.string({ + minLength: 1, + maxLength: 1_000, + }) + ) + ), + count: schema.maybe(schema.nullable(schema.number())), + format: schema.maybe(schema.nullable(serializedFieldFormatSchema)), + }) + ), + }), + }, + }, + router.handleLegacyErrors( + handleErrors( + assertIndexPatternsContext(async (ctx, req, res) => { + const ip = ctx.indexPatterns.indexPatterns; + const id = req.params.id; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + refresh_fields = true, + fields, + } = req.body; + const fieldNames = Object.keys(fields); + + if (fieldNames.length < 1) { + throw new Error('No fields provided.'); + } + + const indexPattern = await ip.get(id); + + let changeCount = 0; + for (const fieldName of fieldNames) { + const field = fields[fieldName]; + + if (field.customLabel !== undefined) { + changeCount++; + indexPattern.setFieldCustomLabel(fieldName, field.customLabel); + } + + if (field.count !== undefined) { + changeCount++; + indexPattern.setFieldCount(fieldName, field.count); + } + + if (field.format !== undefined) { + changeCount++; + if (field.format) { + indexPattern.setFieldFormat(fieldName, field.format); + } else { + indexPattern.deleteFieldFormat(fieldName); + } + } + } + + if (changeCount < 1) { + throw new Error('Index pattern change set is empty.'); + } + + await ip.updateSavedObject(indexPattern); + + if (refresh_fields) { + await ip.refreshFields(indexPattern); + } + + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) + ) + ) + ); +}; From d7dafdbbefd837465f77776c8d5927d2a3eb9837 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 20:13:16 +0100 Subject: [PATCH 59/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20improve=20index=20?= =?UTF-8?q?patterns=20fields=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes.ts | 7 + .../routes/create_index_pattern.ts | 3 +- .../{update_field.ts => update_fields.ts} | 4 +- .../apis/index_patterns/fields_api/index.ts | 26 + .../fields_api/update_fields/errors.ts | 81 ++++ .../fields_api/update_fields/index.ts | 27 ++ .../fields_api/update_fields/main.ts | 447 ++++++++++++++++++ .../apis/index_patterns/index.js | 1 + 8 files changed, 593 insertions(+), 3 deletions(-) rename src/plugins/data/server/index_patterns/routes/fields/{update_field.ts => update_fields.ts} (96%) create mode 100644 test/api_integration/apis/index_patterns/fields_api/index.ts create mode 100644 test/api_integration/apis/index_patterns/fields_api/update_fields/errors.ts create mode 100644 test/api_integration/apis/index_patterns/fields_api/update_fields/index.ts create mode 100644 test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 69fd08e3261fa..66dd005156fb5 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -24,6 +24,7 @@ import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; import { registerDeleteIndexPatternRoute } from './routes/delete_index_pattern'; import { registerUpdateIndexPatternRoute } from './routes/update_index_pattern'; +import { registerUpdateFieldsRoute } from './routes/fields/update_fields'; import { registerCreateScriptedFieldRoute } from './routes/scripted_fields/create_scripted_field'; import { registerPutScriptedFieldRoute } from './routes/scripted_fields/put_scripted_field'; import { registerGetScriptedFieldRoute } from './routes/scripted_fields/get_scripted_field'; @@ -43,10 +44,16 @@ export function registerRoutes(http: HttpServiceSetup) { const router = http.createRouter(); + // Index Patterns API registerCreateIndexPatternRoute(router); registerGetIndexPatternRoute(router); registerDeleteIndexPatternRoute(router); registerUpdateIndexPatternRoute(router); + + // Fields API + registerUpdateFieldsRoute(router); + + // Scripted Field API registerCreateScriptedFieldRoute(router); registerPutScriptedFieldRoute(router); registerGetScriptedFieldRoute(router); diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 5265acfad5dc3..2d0b7df01ff3c 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -46,7 +46,8 @@ const indexPatternSpecSchema = schema.object({ schema.recordOf( schema.string(), schema.object({ - customName: schema.string(), + customLabel: schema.maybe(schema.string()), + count: schema.maybe(schema.number()), }) ) ), diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts similarity index 96% rename from src/plugins/data/server/index_patterns/routes/fields/update_field.ts rename to src/plugins/data/server/index_patterns/routes/fields/update_fields.ts index 0ec1920ec7909..11e7c9816a43b 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_field.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts @@ -23,7 +23,7 @@ import { assertIndexPatternsContext } from '../util/assert_index_patterns_contex import { handleErrors } from '../util/handle_errors'; import { serializedFieldFormatSchema } from '../util/schemas'; -export const registerUpdateScriptedFieldRoute = (router: IRouter) => { +export const registerUpdateFieldsRoute = (router: IRouter) => { router.post( { path: '/api/index_patterns/index_pattern/{id}/fields', @@ -103,7 +103,7 @@ export const registerUpdateScriptedFieldRoute = (router: IRouter) => { } if (changeCount < 1) { - throw new Error('Index pattern change set is empty.'); + throw new Error('Change set is empty.'); } await ip.updateSavedObject(indexPattern); diff --git a/test/api_integration/apis/index_patterns/fields_api/index.ts b/test/api_integration/apis/index_patterns/fields_api/index.ts new file mode 100644 index 0000000000000..1e8fab4963378 --- /dev/null +++ b/test/api_integration/apis/index_patterns/fields_api/index.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('fields_api', () => { + loadTestFile(require.resolve('./update_fields')); + }); +} diff --git a/test/api_integration/apis/index_patterns/fields_api/update_fields/errors.ts b/test/api_integration/apis/index_patterns/fields_api/update_fields/errors.ts new file mode 100644 index 0000000000000..3db6820be6414 --- /dev/null +++ b/test/api_integration/apis/index_patterns/fields_api/update_fields/errors.ts @@ -0,0 +1,81 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('errors', () => { + it('returns 404 error on non-existing index_pattern', async () => { + const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; + const response = await supertest.post(`/api/index_patterns/index_pattern/${id}/fields`).send({ + fields: { + foo: {}, + }, + }); + + expect(response.status).to.be(404); + }); + + it('returns error when "fields" payload attribute is invalid', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: 123, + }); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be( + '[request body.fields]: expected value of type [object] but got [number]' + ); + }); + + it('returns error if not changes are specified', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: {}, + bar: {}, + baz: {}, + }, + }); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be('Change set is empty.'); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/fields_api/update_fields/index.ts b/test/api_integration/apis/index_patterns/fields_api/update_fields/index.ts new file mode 100644 index 0000000000000..a5edb1d02621b --- /dev/null +++ b/test/api_integration/apis/index_patterns/fields_api/update_fields/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('update_fields', () => { + loadTestFile(require.resolve('./errors')); + loadTestFile(require.resolve('./main')); + }); +} diff --git a/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts b/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts new file mode 100644 index 0000000000000..58f2e0a9c6af0 --- /dev/null +++ b/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts @@ -0,0 +1,447 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('main', () => { + it('can update multiple fields', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo).to.be(undefined); + expect(response1.body.index_pattern.fieldAttrs.bar).to.be(undefined); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + count: 123, + customLabel: 'test', + }, + bar: { + count: 456, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo.count).to.be(123); + expect(response2.body.index_pattern.fieldAttrs.foo.customLabel).to.be('test'); + expect(response2.body.index_pattern.fieldAttrs.bar.count).to.be(456); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo.count).to.be(123); + expect(response3.body.index_pattern.fieldAttrs.foo.customLabel).to.be('test'); + expect(response3.body.index_pattern.fieldAttrs.bar.count).to.be(456); + }); + + describe('count', () => { + it('can set field "count" attribute on non-existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo).to.be(undefined); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + count: 123, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo.count).to.be(123); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo.count).to.be(123); + }); + + it('can update "count" attribute in index_pattern attribute map', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldAttrs: { + foo: { + count: 1, + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo.count).to.be(1); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + count: 2, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo.count).to.be(2); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo.count).to.be(2); + }); + + it('can set field "count" attribute on an existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + count: 123, + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo).to.be(undefined); + expect(response1.body.index_pattern.fields.foo.count).to.be(123); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + count: 456, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo).to.be(undefined); + expect(response2.body.index_pattern.fields.foo.count).to.be(456); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo).to.be(undefined); + expect(response3.body.index_pattern.fields.foo.count).to.be(456); + }); + }); + + describe('customLabel', () => { + it('can set field "customLabel" attribute on non-existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo).to.be(undefined); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + customLabel: 'foo', + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo.customLabel).to.be('foo'); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo.customLabel).to.be('foo'); + }); + + it('can update "customLabel" attribute in index_pattern attribute map', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldAttrs: { + foo: { + customLabel: 'foo', + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo.customLabel).to.be('foo'); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + customLabel: 'bar', + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo.customLabel).to.be('bar'); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo.customLabel).to.be('bar'); + }); + + it('can set field "customLabel" attribute on an existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + count: 123, + customLabel: 'foo', + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo).to.be(undefined); + expect(response1.body.index_pattern.fields.foo.customLabel).to.be('foo'); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + customLabel: 'baz', + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo).to.be(undefined); + expect(response2.body.index_pattern.fields.foo.customLabel).to.be('baz'); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo).to.be(undefined); + expect(response3.body.index_pattern.fields.foo.customLabel).to.be('baz'); + }); + }); + + describe('format', () => { + it('can set field "format" attribute on non-existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldFormats.foo).to.be(undefined); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + format: { + id: 'bar', + params: { baz: 'qux' }, + }, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'bar', + params: { baz: 'qux' }, + }); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'bar', + params: { baz: 'qux' }, + }); + }); + + it('can update "format" attribute in index_pattern format map', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldFormats: { + foo: { + id: 'bar', + params: { + baz: 'qux', + }, + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'bar', + params: { + baz: 'qux', + }, + }); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + format: { + id: 'bar-2', + params: { baz: 'qux-2' }, + }, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'bar-2', + params: { baz: 'qux-2' }, + }); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'bar-2', + params: { baz: 'qux-2' }, + }); + }); + + it('can set field "format" on an existing field', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fields: { + foo: { + name: 'foo', + type: 'string', + scripted: true, + format: { + id: 'string', + }, + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldFormats.foo).to.be(undefined); + expect(response1.body.index_pattern.fields.foo.format).to.eql({ + id: 'string', + }); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + format: { id: 'number' }, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'number', + }); + expect(response2.body.index_pattern.fields.foo.format).to.eql({ + id: 'number', + }); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'number', + }); + expect(response3.body.index_pattern.fields.foo.format).to.eql({ + id: 'number', + }); + }); + }); + }); +} diff --git a/test/api_integration/apis/index_patterns/index.js b/test/api_integration/apis/index_patterns/index.js index c7ed1f240a6ea..8195acad3ab65 100644 --- a/test/api_integration/apis/index_patterns/index.js +++ b/test/api_integration/apis/index_patterns/index.js @@ -24,5 +24,6 @@ export default function ({ loadTestFile }) { loadTestFile(require.resolve('./fields_for_wildcard_route')); loadTestFile(require.resolve('./index_pattern_crud')); loadTestFile(require.resolve('./scripted_fields_crud')); + loadTestFile(require.resolve('./fields_api')); }); } From 987fe35ac3c22c7ef8a1f1859a112fb6590d83cd Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 20:24:55 +0100 Subject: [PATCH 60/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20fix=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_pattern_crud/create_index_pattern/main.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts index 45311fed2d31d..85df25332975b 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts @@ -204,14 +204,16 @@ export default function ({ getService }: FtrProviderContext) { title, fieldAttrs: { foo: { - customName: 'bar', + count: 123, + customLabel: 'test', }, }, }, }); expect(response.status).to.be(200); - expect(response.body.index_pattern.fieldAttrs.foo.customName).to.be('bar'); + expect(response.body.index_pattern.fieldAttrs.foo.count).to.be(123); + expect(response.body.index_pattern.fieldAttrs.foo.customLabel).to.be('test'); }); describe('when creating index pattern with existing title', () => { From 357fdbffa4d5f0e7528622c1d49c4a80ed2b7a97 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 20:38:10 +0100 Subject: [PATCH 61/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20doc?= =?UTF-8?q?s=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 154 +++++++++++++++++++++++++++++-------- 1 file changed, 120 insertions(+), 34 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index ecff1ddb35d57..2cd5139493e5b 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -52,25 +52,26 @@ Coming soon. Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: -- Create an index pattern — `POST /api/index_patterns/index_pattern` -- Fetch an index pattern by `{id}` — `GET /api/index_patterns/index_pattern/{id}` -- Delete an index pattern by `{id}` — `DELETE /api/index_patterns/index_pattern/{id}` -- Partially update an index pattern by `{id}` — `POST /api/index_patterns/index_pattern/{id}` - - `title` - - `timeFieldName` - - `intervalName` - - `fields` - - Optionally refresh fields. - - `sourceFilters` - - `fieldFormatMap` - - `type` - - `typeMeta` +- Index Patterns API + - Create an index pattern — `POST /api/index_patterns/index_pattern` + - Fetch an index pattern by `{id}` — `GET /api/index_patterns/index_pattern/{id}` + - Delete an index pattern by `{id}` — `DELETE /api/index_patterns/index_pattern/{id}` + - Partially update an index pattern by `{id}` — `POST /api/index_patterns/index_pattern/{id}` - Fields API - - Create a field — `POST /api/index_patterns/index_pattern/{id}/field` - - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/field` - - Fetch a field — `GET /api/index_patterns/index_pattern/{id}/field/{name}` - - Remove a field — `DELETE /api/index_patterns/index_pattern/{id}/field/{name}` - - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/field/{name}` + - Update field — `POST /api/index_patterns/index_pattern/{id}/fields` +- Scripted Fields API + - Create a field — `POST /api/index_patterns/index_pattern/{id}/scripted_field` + - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/scripted_field` + - Fetch a field — `GET /api/index_patterns/index_pattern/{id}/scripted_field/{name}` + - Remove a field — `DELETE /api/index_patterns/index_pattern/{id}/scripted_field/{name}` + - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/scripted_field/{name}` + + +### Index Patterns API + +Index Patterns CURD API allows you to create, retrieve and delete index patterns. I also +exposes an update endpoint which allows you to update specific fields without changing +the rest of the index pattern object. #### Create an index pattern @@ -136,7 +137,7 @@ The endpoint returns the created index pattern object. ``` -### Fetch an index pattern by ID +#### Fetch an index pattern by ID Retrieve and index pattern by its ID. @@ -165,7 +166,7 @@ Returns an index pattern object. ``` -### Delete an index pattern by ID +#### Delete an index pattern by ID Delete and index pattern by its ID. @@ -176,11 +177,21 @@ DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Returns an '200 OK` response with empty body on success. -### Partially update an index pattern by ID +#### Partially update an index pattern by ID Update part of an index pattern. Only provided fields will be updated on the index pattern, missing fields will stay as they are persisted. +These fields can be update partially: + - `title` + - `timeFieldName` + - `intervalName` + - `fields` (optionally refresh fields) + - `sourceFilters` + - `fieldFormatMap` + - `type` + - `typeMeta` + Update a title of an index pattern. ``` @@ -236,15 +247,90 @@ This endpoint returns the updated index pattern object. ### Fields API -Fields allows you to manage fields of an existing index pattern. +Fields API allows to change field metadata, such as `count`, `customLabel`, and `format`. + + +#### Update fields + +Update endpoint allows you to update fields presentation metadata, such as `count`, +`customLabel`, and `format`. You can update multiple fields in one request. Updates +are merges with persisted metadata. To remove existing metadata specify `null` as value. + +Set popularity `count` for field `foo`: + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fields +{ + "fields": { + "foo": { + "count": 123 + } + } +} +``` + +Update multiple metadata values and fields in one request: + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fields +{ + "fields": { + "foo": { + "count": 123, + "customLabel": "Foo" + }, + "bar": { + "customLabel": "Bar" + } + } +} +``` + +Use `null` value to delete metadata: + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fields +{ + "fields": { + "foo": { + "customLabel": null + } + } +} +``` + +You can skip field refresh using `refresh_fields` flag. `refresh_fields` defaults to `true`. + +``` +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fields +{ + "refresh_fields": false, + "fields": {} +} +``` + +This endpoint returns the updated index pattern object. + +```json +{ + "index_pattern": { + + } +} +``` + + +### Scripted Fields API + +Scripted Fields API provides CRUD API for scripted fields of an index pattern. -#### Create a field +#### Create a scripted field Create a field by simply specifying its name, will default to `string` type. Returns an error if a field with the provided name already exists. ``` -POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/scripted_field { "field": { "name": "my_field" @@ -255,7 +341,7 @@ POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fiel Create a field by specifying all field properties. ``` -POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/scripted_field { "field": { "name": "", @@ -278,14 +364,14 @@ POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fiel } ``` -#### Upsert a field +#### Upsert a scripted field Creates a new field or updates an existing one, if one already exists with the same name. Create a field by simply specifying its name. ``` -PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/scripted_field { "field": { "name": "my_field" @@ -296,7 +382,7 @@ PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field Create a field by specifying all field properties. ``` -PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field +PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/scripted_field { "field": { "name": "", @@ -319,12 +405,12 @@ PUT /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field } ``` -#### Fetch a field +#### Fetch a scripted field Fetch an existing index pattern field by field name. ``` -GET /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/ +GET /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/scripted_field/ ``` Returns the field object. @@ -335,15 +421,15 @@ Returns the field object. } ``` -#### Delete a field +#### Delete a scripted field Delete a field of an index pattern. ``` -DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/ +DELETE /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/scripted_field/ ``` -#### Update a an existing field +#### Update a an existing scripted field Updates an exiting field by mergin provided properties with the existing ones. If there is no existing field with the specified name, returns a `404 Not Found` error. @@ -351,7 +437,7 @@ there is no existing field with the specified name, returns a `404 Not Found` er You can specify any field properties, except `name` which is specified in the URL path. ``` -POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/field/ +POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/scripted_field/ { "field": { "type": "", From 393bbdfed6def23f88b51b8d9f122baa92f55bbb Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 20:48:31 +0100 Subject: [PATCH 62/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20field=20meta?= =?UTF-8?q?data=20deletion=20teests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fields_api/update_fields/main.ts | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts b/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts index 58f2e0a9c6af0..861987c30705c 100644 --- a/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts +++ b/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts @@ -135,6 +135,43 @@ export default function ({ getService }: FtrProviderContext) { expect(response3.body.index_pattern.fieldAttrs.foo.count).to.be(2); }); + it('can delete "count" attribute from index_pattern attribute map', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldAttrs: { + foo: { + count: 1, + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo.count).to.be(1); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + count: null, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo.count).to.be(undefined); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo.count).to.be(undefined); + }); + it('can set field "count" attribute on an existing field', async () => { const title = `foo-${Date.now()}-${Math.random()}*`; const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ @@ -248,6 +285,43 @@ export default function ({ getService }: FtrProviderContext) { expect(response3.body.index_pattern.fieldAttrs.foo.customLabel).to.be('bar'); }); + it('can delete "customLabel" attribute from index_pattern attribute map', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldAttrs: { + foo: { + customLabel: 'foo', + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldAttrs.foo.customLabel).to.be('foo'); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + customLabel: null, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldAttrs.foo.customLabel).to.be(undefined); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldAttrs.foo.customLabel).to.be(undefined); + }); + it('can set field "customLabel" attribute on an existing field', async () => { const title = `foo-${Date.now()}-${Math.random()}*`; const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ @@ -388,6 +462,51 @@ export default function ({ getService }: FtrProviderContext) { }); }); + it('can remove "format" attribute from index_pattern format map', async () => { + const title = `foo-${Date.now()}-${Math.random()}*`; + const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title, + fieldFormats: { + foo: { + id: 'bar', + params: { + baz: 'qux', + }, + }, + }, + }, + }); + + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fieldFormats.foo).to.eql({ + id: 'bar', + params: { + baz: 'qux', + }, + }); + + const response2 = await supertest + .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .send({ + fields: { + foo: { + format: null, + }, + }, + }); + + expect(response2.status).to.be(200); + expect(response2.body.index_pattern.fieldFormats.foo).to.be(undefined); + + const response3 = await supertest.get( + `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + ); + + expect(response3.status).to.be(200); + expect(response3.body.index_pattern.fieldFormats.foo).to.be(undefined); + }); + it('can set field "format" on an existing field', async () => { const title = `foo-${Date.now()}-${Math.random()}*`; const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ From a2e4744ddf446edad4dc926b1bb2781d85ec432f Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 30 Nov 2020 20:48:46 +0100 Subject: [PATCH 63/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20improve=20in?= =?UTF-8?q?dex=20pattern=20api=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index 2cd5139493e5b..e345ed2275bb3 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -60,11 +60,11 @@ Index patterns provide Rest-like HTTP CRUD+ API with the following endpoints: - Fields API - Update field — `POST /api/index_patterns/index_pattern/{id}/fields` - Scripted Fields API - - Create a field — `POST /api/index_patterns/index_pattern/{id}/scripted_field` - - Upsert a field — `PUT /api/index_patterns/index_pattern/{id}/scripted_field` - - Fetch a field — `GET /api/index_patterns/index_pattern/{id}/scripted_field/{name}` - - Remove a field — `DELETE /api/index_patterns/index_pattern/{id}/scripted_field/{name}` - - Update a an existing field — `POST /api/index_patterns/index_pattern/{id}/scripted_field/{name}` + - Create a scripted field — `POST /api/index_patterns/index_pattern/{id}/scripted_field` + - Upsert a scripted field — `PUT /api/index_patterns/index_pattern/{id}/scripted_field` + - Fetch a scripted field — `GET /api/index_patterns/index_pattern/{id}/scripted_field/{name}` + - Remove a scripted field — `DELETE /api/index_patterns/index_pattern/{id}/scripted_field/{name}` + - Update a scripted field — `POST /api/index_patterns/index_pattern/{id}/scripted_field/{name}` ### Index Patterns API From edc7b055a32d1100aef6592899c5ed7aa472a423 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 15:52:24 +0100 Subject: [PATCH 64/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20TypeScript=20?= =?UTF-8?q?errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discover/public/application/helpers/popularize_field.ts | 3 ++- .../public/components/field_editor/field_editor.test.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/discover/public/application/helpers/popularize_field.ts b/src/plugins/discover/public/application/helpers/popularize_field.ts index 0aea86e47c954..4a23844830a39 100644 --- a/src/plugins/discover/public/application/helpers/popularize_field.ts +++ b/src/plugins/discover/public/application/helpers/popularize_field.ts @@ -30,7 +30,8 @@ async function popularizeField( return; } - field.count++; + field.count = 1 + (field.count || 0); + // Catch 409 errors caused by user adding columns in a higher frequency that the changes can be persisted to Elasticsearch try { await indexPatternsService.updateSavedObject(indexPattern, 0, true); diff --git a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx index c9f5f1fcb4a31..55fc1e6eb521e 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx +++ b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx @@ -200,7 +200,7 @@ describe('FieldEditor', () => { }, }; indexPattern.fieldFormatMap = { test: field }; - indexPattern.deleteFieldFormat = jest.fn(); + (indexPattern.deleteFieldFormat as any) = jest.fn(); const component = createComponentWithContext( FieldEditor, From e650438e675965e58c137756368155dc757a9a03 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 15:58:13 +0100 Subject: [PATCH 65/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20update=20jest=20te?= =?UTF-8?q?sts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/index_pattern.test.ts.snap | 1 + .../index_patterns/index_patterns/index_patterns.test.ts | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap b/src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap index e2bdb0009c20a..19ec286307a09 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap +++ b/src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap @@ -687,6 +687,7 @@ Object { }, }, "id": "test-pattern", + "intervalName": undefined, "sourceFilters": undefined, "timeFieldName": "timestamp", "title": "title", diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts index 281633287a4fd..8b73761f9f53b 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts @@ -200,15 +200,6 @@ describe('IndexPatterns', () => { expect(indexPatterns.createSavedObject).toBeCalled(); expect(indexPatterns.setDefault).toBeCalled(); }); - - test('when `makeDefault` is false, does not make the new index pattern the default index pattern', async () => { - const title = 'kibana-*'; - indexPatterns.createSavedObject = jest.fn(); - indexPatterns.setDefault = jest.fn(); - await indexPatterns.createAndSave({ title }, false, false); - expect(indexPatterns.createSavedObject).toBeCalled(); - expect(indexPatterns.setDefault).not.toBeCalled(); - }); }); test('savedObjectToSpec', () => { From dadcad49504ccdb9aee42f01d36c6a012fb07036 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:05:03 +0100 Subject: [PATCH 66/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20aut?= =?UTF-8?q?o-generated=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...a-public.indexpattern.deletefieldformat.md | 2 +- ...plugin-plugins-data-public.indexpattern.md | 3 +++ ...-data-public.indexpattern.setfieldattrs.md | 24 +++++++++++++++++++ ...-data-public.indexpattern.setfieldcount.md | 23 ++++++++++++++++++ ...public.indexpattern.setfieldcustomlabel.md | 23 ++++++++++++++++++ ...data-public.indexpattern.setfieldformat.md | 2 +- ...ins-data-public.indexpatternfield.count.md | 4 ++-- ...n-plugins-data-public.indexpatternfield.md | 2 +- ...ns-data-public.indexpatternfield.tojson.md | 4 ++-- .../kibana-plugin-plugins-data-public.md | 2 +- ...blic.searchsessioninfoprovider.getname.md} | 2 +- ...essioninfoprovider.geturlgeneratordata.md} | 2 +- ...-data-public.searchsessioninfoprovider.md} | 6 ++--- ...a-server.indexpattern.deletefieldformat.md | 2 +- ...plugin-plugins-data-server.indexpattern.md | 3 +++ ...-data-server.indexpattern.setfieldattrs.md | 24 +++++++++++++++++++ ...-data-server.indexpattern.setfieldcount.md | 23 ++++++++++++++++++ ...server.indexpattern.setfieldcustomlabel.md | 23 ++++++++++++++++++ ...data-server.indexpattern.setfieldformat.md | 2 +- src/plugins/data/public/public.api.md | 18 +++++++++----- src/plugins/data/server/server.api.md | 12 +++++++--- 21 files changed, 182 insertions(+), 24 deletions(-) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldattrs.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcount.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcustomlabel.md rename docs/development/plugins/data/public/{kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.getname.md => kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md} (83%) rename docs/development/plugins/data/public/{kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.geturlgeneratordata.md => kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md} (82%) rename docs/development/plugins/data/public/{kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.md => kibana-plugin-plugins-data-public.searchsessioninfoprovider.md} (84%) create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldattrs.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcount.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcustomlabel.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.deletefieldformat.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.deletefieldformat.md index 26276a809a613..3ef42968d85cd 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.deletefieldformat.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.deletefieldformat.md @@ -7,5 +7,5 @@ Signature: ```typescript -deleteFieldFormat: (fieldName: string) => void; +readonly deleteFieldFormat: (fieldName: string) => void; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md index 6bd2cbc24283f..179148265e68d 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md @@ -59,5 +59,8 @@ export declare class IndexPattern implements IIndexPattern | [isTimeBased()](./kibana-plugin-plugins-data-public.indexpattern.istimebased.md) | | | | [isTimeNanosBased()](./kibana-plugin-plugins-data-public.indexpattern.istimenanosbased.md) | | | | [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | Remove scripted field from field list | +| [setFieldAttrs(fieldName, attrName, value)](./kibana-plugin-plugins-data-public.indexpattern.setfieldattrs.md) | | | +| [setFieldCount(fieldName, count)](./kibana-plugin-plugins-data-public.indexpattern.setfieldcount.md) | | | +| [setFieldCustomLabel(fieldName, customLabel)](./kibana-plugin-plugins-data-public.indexpattern.setfieldcustomlabel.md) | | | | [toSpec()](./kibana-plugin-plugins-data-public.indexpattern.tospec.md) | | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldattrs.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldattrs.md new file mode 100644 index 0000000000000..034081be71cb7 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldattrs.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [setFieldAttrs](./kibana-plugin-plugins-data-public.indexpattern.setfieldattrs.md) + +## IndexPattern.setFieldAttrs() method + +Signature: + +```typescript +protected setFieldAttrs(fieldName: string, attrName: K, value: FieldAttrSet[K]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fieldName | string | | +| attrName | K | | +| value | FieldAttrSet[K] | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcount.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcount.md new file mode 100644 index 0000000000000..c0783a6b13270 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcount.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [setFieldCount](./kibana-plugin-plugins-data-public.indexpattern.setfieldcount.md) + +## IndexPattern.setFieldCount() method + +Signature: + +```typescript +setFieldCount(fieldName: string, count: number | undefined | null): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fieldName | string | | +| count | number | undefined | null | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcustomlabel.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcustomlabel.md new file mode 100644 index 0000000000000..174041ba9736a --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldcustomlabel.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [setFieldCustomLabel](./kibana-plugin-plugins-data-public.indexpattern.setfieldcustomlabel.md) + +## IndexPattern.setFieldCustomLabel() method + +Signature: + +```typescript +setFieldCustomLabel(fieldName: string, customLabel: string | undefined | null): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fieldName | string | | +| customLabel | string | undefined | null | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldformat.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldformat.md index 9774fc8c7308c..1a705659e8c43 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldformat.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.setfieldformat.md @@ -7,5 +7,5 @@ Signature: ```typescript -setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; +readonly setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md index 1b8e13a38c6d9..f01c6c8b4596b 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md @@ -9,7 +9,7 @@ Count is used for field popularity Signature: ```typescript -get count(): number; +get count(): number | undefined; -set count(count: number); +set count(count: number | undefined); ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md index caf7d374161dd..a98c7601deb4f 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md @@ -22,7 +22,7 @@ export declare class IndexPatternField implements IFieldType | --- | --- | --- | --- | | [aggregatable](./kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md) | | boolean | | | [conflictDescriptions](./kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md) | | Record<string, string[]> | undefined | Description of field type conflicts across different indices in the same index pattern | -| [count](./kibana-plugin-plugins-data-public.indexpatternfield.count.md) | | number | Count is used for field popularity | +| [count](./kibana-plugin-plugins-data-public.indexpatternfield.count.md) | | number | undefined | Count is used for field popularity | | [customLabel](./kibana-plugin-plugins-data-public.indexpatternfield.customlabel.md) | | string | undefined | | | [displayName](./kibana-plugin-plugins-data-public.indexpatternfield.displayname.md) | | string | | | [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | undefined | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md index f0600dd20658a..4960481af3969 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md @@ -8,7 +8,7 @@ ```typescript toJSON(): { - count: number; + count: number | undefined; script: string | undefined; lang: string | undefined; conflictDescriptions: Record | undefined; @@ -26,7 +26,7 @@ toJSON(): { Returns: `{ - count: number; + count: number | undefined; script: string | undefined; lang: string | undefined; conflictDescriptions: Record | undefined; diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index 9121b0aade470..08ed14b92d24c 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -89,7 +89,7 @@ | [SavedQueryService](./kibana-plugin-plugins-data-public.savedqueryservice.md) | | | [SearchError](./kibana-plugin-plugins-data-public.searcherror.md) | | | [SearchInterceptorDeps](./kibana-plugin-plugins-data-public.searchinterceptordeps.md) | | -| [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md) | Provide info about current search session to be stored in backgroundSearch saved object | +| [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) | Provide info about current search session to be stored in backgroundSearch saved object | | [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) | search source fields | | [TabbedAggColumn](./kibana-plugin-plugins-data-public.tabbedaggcolumn.md) | \* | | [TabbedTable](./kibana-plugin-plugins-data-public.tabbedtable.md) | \* | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.getname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md similarity index 83% rename from docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.getname.md rename to docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md index 0f0b616066dd6..2a5e1d2a3135f 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.getname.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md @@ -1,6 +1,6 @@ -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md) > [getName](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.getname.md) +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) > [getName](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md) ## SearchSessionInfoProvider.getName property diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.geturlgeneratordata.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md similarity index 82% rename from docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.geturlgeneratordata.md rename to docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md index 207adaf2bd50b..01558ed3dddad 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.geturlgeneratordata.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md @@ -1,6 +1,6 @@ -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md) > [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.geturlgeneratordata.md) +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) > [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md) ## SearchSessionInfoProvider.getUrlGeneratorData property diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.md similarity index 84% rename from docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.md rename to docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.md index a3d294f5e3303..bcc4a5508eb59 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessionrestorationinfoprovider.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsessioninfoprovider.md @@ -1,6 +1,6 @@ -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.md) +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) ## SearchSessionInfoProvider interface @@ -16,6 +16,6 @@ export interface SearchSessionInfoProvider() => Promise<string> | User-facing name of the session. e.g. will be displayed in background sessions management list | -| [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchSessionInfoprovider.geturlgeneratordata.md) | () => Promise<{
urlGeneratorId: ID;
initialState: UrlGeneratorStateMapping[ID]['State'];
restoreState: UrlGeneratorStateMapping[ID]['State'];
}> | | +| [getName](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.getname.md) | () => Promise<string> | User-facing name of the session. e.g. will be displayed in background sessions management list | +| [getUrlGeneratorData](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.geturlgeneratordata.md) | () => Promise<{
urlGeneratorId: ID;
initialState: UrlGeneratorStateMapping[ID]['State'];
restoreState: UrlGeneratorStateMapping[ID]['State'];
}> | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.deletefieldformat.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.deletefieldformat.md index 4bfda56527474..9f580b2e3b48b 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.deletefieldformat.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.deletefieldformat.md @@ -7,5 +7,5 @@ Signature: ```typescript -deleteFieldFormat: (fieldName: string) => void; +readonly deleteFieldFormat: (fieldName: string) => void; ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.md index e5e2dfd0999db..b2cb217fecaa2 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.md @@ -59,5 +59,8 @@ export declare class IndexPattern implements IIndexPattern | [isTimeBased()](./kibana-plugin-plugins-data-server.indexpattern.istimebased.md) | | | | [isTimeNanosBased()](./kibana-plugin-plugins-data-server.indexpattern.istimenanosbased.md) | | | | [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-server.indexpattern.removescriptedfield.md) | | Remove scripted field from field list | +| [setFieldAttrs(fieldName, attrName, value)](./kibana-plugin-plugins-data-server.indexpattern.setfieldattrs.md) | | | +| [setFieldCount(fieldName, count)](./kibana-plugin-plugins-data-server.indexpattern.setfieldcount.md) | | | +| [setFieldCustomLabel(fieldName, customLabel)](./kibana-plugin-plugins-data-server.indexpattern.setfieldcustomlabel.md) | | | | [toSpec()](./kibana-plugin-plugins-data-server.indexpattern.tospec.md) | | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldattrs.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldattrs.md new file mode 100644 index 0000000000000..91da8ee14c230 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldattrs.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPattern](./kibana-plugin-plugins-data-server.indexpattern.md) > [setFieldAttrs](./kibana-plugin-plugins-data-server.indexpattern.setfieldattrs.md) + +## IndexPattern.setFieldAttrs() method + +Signature: + +```typescript +protected setFieldAttrs(fieldName: string, attrName: K, value: FieldAttrSet[K]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fieldName | string | | +| attrName | K | | +| value | FieldAttrSet[K] | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcount.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcount.md new file mode 100644 index 0000000000000..f7d6d21c00ef0 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcount.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPattern](./kibana-plugin-plugins-data-server.indexpattern.md) > [setFieldCount](./kibana-plugin-plugins-data-server.indexpattern.setfieldcount.md) + +## IndexPattern.setFieldCount() method + +Signature: + +```typescript +setFieldCount(fieldName: string, count: number | undefined | null): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fieldName | string | | +| count | number | undefined | null | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcustomlabel.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcustomlabel.md new file mode 100644 index 0000000000000..2c15c3ca4f552 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldcustomlabel.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPattern](./kibana-plugin-plugins-data-server.indexpattern.md) > [setFieldCustomLabel](./kibana-plugin-plugins-data-server.indexpattern.setfieldcustomlabel.md) + +## IndexPattern.setFieldCustomLabel() method + +Signature: + +```typescript +setFieldCustomLabel(fieldName: string, customLabel: string | undefined | null): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fieldName | string | | +| customLabel | string | undefined | null | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldformat.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldformat.md index a8f2e726dd9b3..e6a6b9ea2c0f5 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldformat.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.setfieldformat.md @@ -7,5 +7,5 @@ Signature: ```typescript -setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; +readonly setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; ``` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 9e123fa160a8e..a67045d501aa1 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1115,7 +1115,7 @@ export class IndexPattern implements IIndexPattern { constructor({ spec, fieldFormats, shortDotsEnable, metaFields, }: IndexPatternDeps); addScriptedField(name: string, script: string, fieldType?: string): Promise; // (undocumented) - deleteFieldFormat: (fieldName: string) => void; + readonly deleteFieldFormat: (fieldName: string) => void; // Warning: (ae-forgotten-export) The symbol "FieldAttrs" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -1205,7 +1205,13 @@ export class IndexPattern implements IIndexPattern { removeScriptedField(fieldName: string): void; resetOriginalSavedObjectBody: () => void; // (undocumented) - setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; + protected setFieldAttrs(fieldName: string, attrName: K, value: FieldAttrSet[K]): void; + // (undocumented) + setFieldCount(fieldName: string, count: number | undefined | null): void; + // (undocumented) + setFieldCustomLabel(fieldName: string, customLabel: string | undefined | null): void; + // (undocumented) + readonly setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; // Warning: (ae-forgotten-export) The symbol "SourceFilter" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -1269,8 +1275,8 @@ export class IndexPatternField implements IFieldType { get aggregatable(): boolean; get conflictDescriptions(): Record | undefined; set conflictDescriptions(conflictDescriptions: Record | undefined); - get count(): number; - set count(count: number); + get count(): number | undefined; + set count(count: number | undefined); // (undocumented) get customLabel(): string | undefined; set customLabel(customLabel: string | undefined); @@ -1300,7 +1306,7 @@ export class IndexPatternField implements IFieldType { get subType(): import("../types").IFieldSubType | undefined; // (undocumented) toJSON(): { - count: number; + count: number | undefined; script: string | undefined; lang: string | undefined; conflictDescriptions: Record | undefined; @@ -2404,7 +2410,7 @@ export const UI_SETTINGS: { // src/plugins/data/common/es_query/filters/phrase_filter.ts:33:3 - (ae-forgotten-export) The symbol "PhraseFilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/es_query/filters/phrases_filter.ts:31:3 - (ae-forgotten-export) The symbol "PhrasesFilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:64:5 - (ae-forgotten-export) The symbol "FormatFieldFn" needs to be exported by the entry point index.d.ts -// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:136:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:128:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts // src/plugins/data/common/search/aggs/types.ts:113:51 - (ae-forgotten-export) The symbol "AggTypesRegistryStart" needs to be exported by the entry point index.d.ts // src/plugins/data/public/field_formats/field_formats_service.ts:67:3 - (ae-forgotten-export) The symbol "FormatFactory" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:66:23 - (ae-forgotten-export) The symbol "FILTERS" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index bf4dec2573ebb..d356b6bf48646 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -555,7 +555,7 @@ export class IndexPattern implements IIndexPattern { constructor({ spec, fieldFormats, shortDotsEnable, metaFields, }: IndexPatternDeps); addScriptedField(name: string, script: string, fieldType?: string): Promise; // (undocumented) - deleteFieldFormat: (fieldName: string) => void; + readonly deleteFieldFormat: (fieldName: string) => void; // Warning: (ae-forgotten-export) The symbol "FieldAttrs" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -648,10 +648,16 @@ export class IndexPattern implements IIndexPattern { metaFields: string[]; removeScriptedField(fieldName: string): void; resetOriginalSavedObjectBody: () => void; + // (undocumented) + protected setFieldAttrs(fieldName: string, attrName: K, value: FieldAttrSet[K]): void; + // (undocumented) + setFieldCount(fieldName: string, count: number | undefined | null): void; + // (undocumented) + setFieldCustomLabel(fieldName: string, customLabel: string | undefined | null): void; // Warning: (ae-forgotten-export) The symbol "SerializedFieldFormat" needs to be exported by the entry point index.d.ts // // (undocumented) - setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; + readonly setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void; // Warning: (ae-forgotten-export) The symbol "SourceFilter" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -1217,7 +1223,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/common/es_query/filters/meta_filter.ts:54:3 - (ae-forgotten-export) The symbol "FilterMeta" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:58:45 - (ae-forgotten-export) The symbol "IndexPatternFieldMap" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:64:5 - (ae-forgotten-export) The symbol "FormatFieldFn" needs to be exported by the entry point index.d.ts -// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:136:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:128:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildCustomFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:57:23 - (ae-forgotten-export) The symbol "datatableToCSV" needs to be exported by the entry point index.d.ts From 7ef24498cf0dca25fe3679f3ea7f91dc4251b49a Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:14:42 +0100 Subject: [PATCH 67/93] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20remove=20intervalN?= =?UTF-8?q?ame=20from=20index=20pattern=20create=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/routes/create_index_pattern.ts | 1 - .../index_pattern_crud/create_index_pattern/main.ts | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 2d0b7df01ff3c..41fc8d2a5164e 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -30,7 +30,6 @@ const indexPatternSpecSchema = schema.object({ id: schema.maybe(schema.string()), version: schema.maybe(schema.string()), type: schema.maybe(schema.string()), - intervalName: schema.maybe(schema.string()), timeFieldName: schema.maybe(schema.string()), sourceFilters: schema.maybe( schema.arrayOf( diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts index 85df25332975b..75820e157afe6 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts @@ -58,7 +58,6 @@ export default function ({ getService }: FtrProviderContext) { id, version: 'test-version', type: 'test-type', - intervalName: 'test-intervalName', timeFieldName: 'test-timeFieldName', }, }); @@ -68,7 +67,6 @@ export default function ({ getService }: FtrProviderContext) { expect(response.body.index_pattern.id).to.be(id); expect(response.body.index_pattern.version).to.be('test-version'); expect(response.body.index_pattern.type).to.be('test-type'); - expect(response.body.index_pattern.intervalName).to.be('test-intervalName'); expect(response.body.index_pattern.timeFieldName).to.be('test-timeFieldName'); }); @@ -239,22 +237,22 @@ export default function ({ getService }: FtrProviderContext) { const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ index_pattern: { title, - intervalName: 'foo', + timeFieldName: 'foo', }, }); const response2 = await supertest.post('/api/index_patterns/index_pattern').send({ override: true, index_pattern: { title, - intervalName: 'bar', + timeFieldName: 'bar', }, }); expect(response1.status).to.be(200); expect(response2.status).to.be(200); - expect(response1.body.index_pattern.intervalName).to.be('foo'); - expect(response2.body.index_pattern.intervalName).to.be('bar'); + expect(response1.body.index_pattern.timeFieldName).to.be('foo'); + expect(response2.body.index_pattern.timeFieldName).to.be('bar'); expect(response1.body.index_pattern.id).to.be(response1.body.index_pattern.id); }); From 10aae1ecfb9d640e503fe70adafd5dd7e0f2b0e4 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:17:04 +0100 Subject: [PATCH 68/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20fix=20integration?= =?UTF-8?q?=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_pattern_crud/update_index_pattern/main.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts index 304f9ce66e799..1e04f1579d619 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts @@ -79,11 +79,10 @@ export default function ({ getService }: FtrProviderContext) { const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ index_pattern: { title, - intervalName: 'intervalName1', }, }); - expect(response1.body.index_pattern.intervalName).to.be('intervalName1'); + expect(response1.body.index_pattern.intervalName).to.be(undefined); const id = response1.body.index_pattern.id; const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ @@ -311,19 +310,18 @@ export default function ({ getService }: FtrProviderContext) { expect(response3.body.index_pattern.fields.bar.aggregatable).to.be(true); }); - it('can multiple index pattern fields at once', async () => { + it('can update multiple index pattern fields at once', async () => { const title = `foo-${Date.now()}-${Math.random()}*`; const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ index_pattern: { title, timeFieldName: 'timeFieldName1', - intervalName: 'intervalName1', typeMeta: { foo: 'bar' }, }, }); expect(response1.body.index_pattern.timeFieldName).to.be('timeFieldName1'); - expect(response1.body.index_pattern.intervalName).to.be('intervalName1'); + expect(response1.body.index_pattern.intervalName).to.be(undefined); expect(response1.body.index_pattern.typeMeta.foo).to.be('bar'); const id = response1.body.index_pattern.id; From 8062fb56df68342477f6c924a68369c08c4e354a Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:19:12 +0100 Subject: [PATCH 69/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20make=20refresh=5Ffi?= =?UTF-8?q?elds=20default=20to=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes/create_index_pattern.ts | 2 +- .../data/server/index_patterns/routes/fields/update_fields.ts | 2 +- .../routes/scripted_fields/create_scripted_field.ts | 2 +- .../index_patterns/routes/scripted_fields/put_scripted_field.ts | 2 +- .../routes/scripted_fields/update_scripted_field.ts | 2 +- .../data/server/index_patterns/routes/update_index_pattern.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 41fc8d2a5164e..b23c8d37fbf27 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -59,7 +59,7 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { validate: { body: schema.object({ override: schema.maybe(schema.boolean({ defaultValue: false })), - refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), index_pattern: indexPatternSpecSchema, }), }, diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts index 11e7c9816a43b..4ab25873352ec 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts @@ -38,7 +38,7 @@ export const registerUpdateFieldsRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), fields: schema.recordOf( schema.string({ minLength: 1, diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 381cbde77bac6..7222c71f48d90 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -38,7 +38,7 @@ export const registerCreateScriptedFieldRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), field: fieldSpecSchema, }), }, diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index b85377be398fb..51c2ccda70245 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -38,7 +38,7 @@ export const registerPutScriptedFieldRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), field: fieldSpecSchema, }), }, diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index c5313cc3be51a..6886d3e4f010f 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -44,7 +44,7 @@ export const registerUpdateScriptedFieldRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), field: schema.object({ ...fieldSpecSchemaFields, diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 57a9ea982498f..d6c0f31172217 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -55,7 +55,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: true })), + refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), index_pattern: indexPatternUpdateSchema, }), }, From deb8e975ce3b377ab3afbd57054ca9521282f9b0 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:25:34 +0100 Subject: [PATCH 70/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20searchab?= =?UTF-8?q?le=20and=20aggregatable=20from=20public=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/index_patterns/routes/util/schemas.ts | 2 -- .../index_pattern_crud/create_index_pattern/main.ts | 12 ------------ .../index_pattern_crud/update_index_pattern/main.ts | 10 ---------- .../create_scripted_field/errors.ts | 4 ---- .../create_scripted_field/main.ts | 8 -------- .../delete_scripted_field/errors.ts | 2 -- .../delete_scripted_field/main.ts | 2 -- .../get_scripted_field/errors.ts | 2 -- .../scripted_fields_crud/get_scripted_field/main.ts | 4 ---- .../put_scripted_field/errors.ts | 2 -- .../scripted_fields_crud/put_scripted_field/main.ts | 10 ---------- .../update_scripted_field/main.ts | 4 ---- 12 files changed, 62 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/util/schemas.ts b/src/plugins/data/server/index_patterns/routes/util/schemas.ts index dbfddb28d1ed6..9ef3881983d93 100644 --- a/src/plugins/data/server/index_patterns/routes/util/schemas.ts +++ b/src/plugins/data/server/index_patterns/routes/util/schemas.ts @@ -32,8 +32,6 @@ export const fieldSpecSchemaFields = { defaultValue: 'string', maxLength: 1_000, }), - searchable: schema.boolean({ defaultValue: false }), - aggregatable: schema.boolean({ defaultValue: false }), count: schema.maybe( schema.number({ min: 0, diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts index 75820e157afe6..d26f70ca740e3 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts @@ -97,8 +97,6 @@ export default function ({ getService }: FtrProviderContext) { foo: { name: 'foo', type: 'string', - searchable: false, - aggregatable: false, }, }, }, @@ -108,8 +106,6 @@ export default function ({ getService }: FtrProviderContext) { expect(response.body.index_pattern.title).to.be(title); expect(response.body.index_pattern.fields.foo.name).to.be('foo'); expect(response.body.index_pattern.fields.foo.type).to.be('string'); - expect(response.body.index_pattern.fields.foo.searchable).to.be(false); - expect(response.body.index_pattern.fields.foo.aggregatable).to.be(false); }); it('can add two fields, one with all fields specified', async () => { @@ -121,14 +117,10 @@ export default function ({ getService }: FtrProviderContext) { foo: { name: 'foo', type: 'string', - searchable: false, - aggregatable: false, }, bar: { name: 'bar', type: 'number', - searchable: true, - aggregatable: true, count: 123, script: '', lang: 'test-lang', @@ -148,13 +140,9 @@ export default function ({ getService }: FtrProviderContext) { expect(response.body.index_pattern.fields.foo.name).to.be('foo'); expect(response.body.index_pattern.fields.foo.type).to.be('string'); - expect(response.body.index_pattern.fields.foo.searchable).to.be(false); - expect(response.body.index_pattern.fields.foo.aggregatable).to.be(false); expect(response.body.index_pattern.fields.bar.name).to.be('bar'); expect(response.body.index_pattern.fields.bar.type).to.be('number'); - expect(response.body.index_pattern.fields.bar.searchable).to.be(true); - expect(response.body.index_pattern.fields.bar.aggregatable).to.be(true); expect(response.body.index_pattern.fields.bar.count).to.be(123); expect(response.body.index_pattern.fields.bar.script).to.be(''); expect(response.body.index_pattern.fields.bar.lang).to.be('test-lang'); diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts index 1e04f1579d619..bfc4c23738aef 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/update_index_pattern/main.ts @@ -271,8 +271,6 @@ export default function ({ getService }: FtrProviderContext) { foo: { name: 'foo', type: 'string', - searchable: false, - aggregatable: false, }, }, }, @@ -280,8 +278,6 @@ export default function ({ getService }: FtrProviderContext) { expect(response1.body.index_pattern.fields.foo.name).to.be('foo'); expect(response1.body.index_pattern.fields.foo.type).to.be('string'); - expect(response1.body.index_pattern.fields.foo.searchable).to.be(false); - expect(response1.body.index_pattern.fields.foo.aggregatable).to.be(false); const id = response1.body.index_pattern.id; const response2 = await supertest.post('/api/index_patterns/index_pattern/' + id).send({ @@ -290,8 +286,6 @@ export default function ({ getService }: FtrProviderContext) { bar: { name: 'bar', type: 'number', - searchable: true, - aggregatable: true, }, }, }, @@ -299,15 +293,11 @@ export default function ({ getService }: FtrProviderContext) { expect(response2.body.index_pattern.fields.bar.name).to.be('bar'); expect(response2.body.index_pattern.fields.bar.type).to.be('number'); - expect(response2.body.index_pattern.fields.bar.searchable).to.be(true); - expect(response2.body.index_pattern.fields.bar.aggregatable).to.be(true); const response3 = await supertest.get('/api/index_patterns/index_pattern/' + id); expect(response3.body.index_pattern.fields.bar.name).to.be('bar'); expect(response3.body.index_pattern.fields.bar.type).to.be('number'); - expect(response3.body.index_pattern.fields.bar.searchable).to.be(true); - expect(response3.body.index_pattern.fields.bar.aggregatable).to.be(true); }); it('can update multiple index pattern fields at once', async () => { diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts index d0f7b7feaae91..a3166873fd091 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts @@ -59,8 +59,6 @@ export default function ({ getService }: FtrProviderContext) { name: 'bar', type: 'number', scripted: false, - searchable: true, - aggregatable: true, }, }); @@ -86,8 +84,6 @@ export default function ({ getService }: FtrProviderContext) { name: 'bar', type: 'number', scripted: false, - searchable: true, - aggregatable: true, }, }); diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts index 34b48ec1fb431..3927f3b159521 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/main.ts @@ -40,8 +40,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'number', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }); @@ -50,8 +48,6 @@ export default function ({ getService }: FtrProviderContext) { expect(response2.body.field.type).to.be('number'); expect(response2.body.field.scripted).to.be(true); expect(response2.body.field.script).to.be("doc['field_name'].value"); - expect(response2.body.field.searchable).to.be(true); - expect(response2.body.field.aggregatable).to.be(true); }); it('newly created scripted field is materialized in the index_pattern object', async () => { @@ -70,8 +66,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'number', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }); @@ -87,8 +81,6 @@ export default function ({ getService }: FtrProviderContext) { expect(field.type).to.be('number'); expect(field.scripted).to.be(true); expect(field.script).to.be("doc['field_name'].value"); - expect(field.searchable).to.be(true); - expect(field.aggregatable).to.be(true); }); }); } diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts index 48527cc37e9af..2182f47d91c08 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts @@ -57,8 +57,6 @@ export default function ({ getService }: FtrProviderContext) { scripted: false, name: 'foo', type: 'string', - searchable: false, - aggregatable: false, }, }, }, diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts index c202646a30ace..11dfd5c2171ad 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/main.ts @@ -35,8 +35,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'number', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }, }, diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts index 665ba94ec29d2..1f39de8c03a96 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts @@ -57,8 +57,6 @@ export default function ({ getService }: FtrProviderContext) { scripted: false, name: 'foo', type: 'string', - searchable: false, - aggregatable: false, }, }, }, diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts index eb2019b0e98b8..2a44499be3e90 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/main.ts @@ -35,16 +35,12 @@ export default function ({ getService }: FtrProviderContext) { type: 'string', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, bar: { name: 'bar', type: 'number', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }, }, diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts index e4dca1b15ab5f..8a7e5aae2176f 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/errors.ts @@ -49,8 +49,6 @@ export default function ({ getService }: FtrProviderContext) { scripted: false, name: 'foo', type: 'string', - searchable: false, - aggregatable: false, }, }, }, diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts index ee410576c89fb..d765255f1fe17 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/put_scripted_field/main.ts @@ -35,16 +35,12 @@ export default function ({ getService }: FtrProviderContext) { type: 'string', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, bar: { name: 'bar', type: 'string', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }, }, @@ -58,8 +54,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'number', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }); @@ -93,8 +87,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'string', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }, }, @@ -108,8 +100,6 @@ export default function ({ getService }: FtrProviderContext) { type: 'number', scripted: true, script: "doc['bar'].value", - searchable: true, - aggregatable: true, }, }); diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts index 502370cb32b04..984969ab8d88b 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/update_scripted_field/main.ts @@ -35,16 +35,12 @@ export default function ({ getService }: FtrProviderContext) { type: 'string', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, bar: { name: 'bar', type: 'string', scripted: true, script: "doc['field_name'].value", - searchable: true, - aggregatable: true, }, }, }, From f5b9b4eb64ad4fdc5ca7e282b1bc491d4da8cf88 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:40:48 +0100 Subject: [PATCH 71/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20various?= =?UTF-8?q?=20field=20properties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns/index_patterns.ts | 2 -- .../server/index_patterns/routes/util/schemas.ts | 9 --------- .../index_pattern_crud/create_index_pattern/main.ts | 12 ++---------- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 55e17f512c28e..2ca17ec24c322 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -460,8 +460,6 @@ export class IndexPatternsService { * @param spec * @param override Overwrite if existing index pattern exists. * @param skipFetchFields Whether to skip field refresh step. - * @param makeDefault Whether to make the new index pattern the default - * index pattern. */ async createAndSave(spec: IndexPatternSpec, override = false, skipFetchFields = false) { diff --git a/src/plugins/data/server/index_patterns/routes/util/schemas.ts b/src/plugins/data/server/index_patterns/routes/util/schemas.ts index 9ef3881983d93..7526ba328f3b3 100644 --- a/src/plugins/data/server/index_patterns/routes/util/schemas.ts +++ b/src/plugins/data/server/index_patterns/routes/util/schemas.ts @@ -42,18 +42,9 @@ export const fieldSpecSchemaFields = { maxLength: 1_000_000, }) ), - lang: schema.maybe( - schema.string({ - maxLength: 1_000, - }) - ), - conflictDescriptions: schema.maybe( - schema.recordOf(schema.string(), schema.arrayOf(schema.string())) - ), format: schema.maybe(serializedFieldFormatSchema), esTypes: schema.maybe(schema.arrayOf(schema.string())), scripted: schema.maybe(schema.boolean()), - readFromDocValues: schema.maybe(schema.boolean()), subType: schema.maybe( schema.object({ multi: schema.maybe( diff --git a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts index d26f70ca740e3..bffeaed7cb264 100644 --- a/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts +++ b/test/api_integration/apis/index_patterns/index_pattern_crud/create_index_pattern/main.ts @@ -123,13 +123,8 @@ export default function ({ getService }: FtrProviderContext) { type: 'number', count: 123, script: '', - lang: 'test-lang', - conflictDescriptions: { - foo: ['bar'], - }, esTypes: ['test-type'], - scripted: false, - readFromDocValues: false, + scripted: true, }, }, }, @@ -145,11 +140,8 @@ export default function ({ getService }: FtrProviderContext) { expect(response.body.index_pattern.fields.bar.type).to.be('number'); expect(response.body.index_pattern.fields.bar.count).to.be(123); expect(response.body.index_pattern.fields.bar.script).to.be(''); - expect(response.body.index_pattern.fields.bar.lang).to.be('test-lang'); - expect(response.body.index_pattern.fields.bar.conflictDescriptions.foo[0]).to.be('bar'); expect(response.body.index_pattern.fields.bar.esTypes[0]).to.be('test-type'); - expect(response.body.index_pattern.fields.bar.scripted).to.be(false); - expect(response.body.index_pattern.fields.bar.readFromDocValues).to.be(false); + expect(response.body.index_pattern.fields.bar.scripted).to.be(true); }); it('can specify optional typeMeta attribute when creating an index pattern', async () => { From bd38e4d05fe041d2a141bfe5ef1fc0796c778496 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:45:39 +0100 Subject: [PATCH 72/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20"index"?= =?UTF-8?q?=20attribute=20from=20public=20field=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/index_patterns/index_patterns/index_patterns.ts | 4 ++-- src/plugins/data/server/index_patterns/routes/util/schemas.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 2ca17ec24c322..88801f89a475b 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -281,10 +281,10 @@ export class IndexPatternsService { options: GetFieldsOptions, fieldAttrs: FieldAttrs = {} ) => { - const scriptdFields = Object.values(fields).filter((field) => field.scripted); + const scriptedFields = Object.values(fields).filter((field) => field.scripted); try { const newFields = (await this.getFieldsForWildcard(options)) as FieldSpec[]; - return this.fieldArrayToMap([...newFields, ...scriptdFields], fieldAttrs); + return this.fieldArrayToMap([...newFields, ...scriptedFields], fieldAttrs); } catch (err) { if (err instanceof IndexPatternMissingIndices) { this.onNotification({ title: (err as any).message, color: 'danger', iconType: 'alert' }); diff --git a/src/plugins/data/server/index_patterns/routes/util/schemas.ts b/src/plugins/data/server/index_patterns/routes/util/schemas.ts index 7526ba328f3b3..08b99c727b4a5 100644 --- a/src/plugins/data/server/index_patterns/routes/util/schemas.ts +++ b/src/plugins/data/server/index_patterns/routes/util/schemas.ts @@ -59,7 +59,6 @@ export const fieldSpecSchemaFields = { ), }) ), - indexed: schema.maybe(schema.boolean()), customLabel: schema.maybe(schema.string()), shortDotsEnable: schema.maybe(schema.boolean()), }; From 987ad716572da5157a4d63a4096337698420731b Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 16:48:20 +0100 Subject: [PATCH 73/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20doc?= =?UTF-8?q?s=20to=20match=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index e345ed2275bb3..fe2d9a4cfbf90 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -88,19 +88,16 @@ POST /api/index_patterns/index_pattern Customize creation behavior with: -- `override` --- if set to `true`, replaces an existing index pattern if an +- `override` — if set to `true`, replaces an existing index pattern if an index pattern with the provided title already exists. Defaults to `false`. -- `refresh_fields` --- if set to `false` skips reloading index pattern fields after - the index pattern is stored. Defaults to `true`. -- `make_default` --- if set to `true`, makes the new index pattern the default - index pattern. Defaults to `true`. +- `refresh_fields` — if set to `true` reloads index pattern fields after + the index pattern is stored. Defaults to `false`. ``` POST /api/index_patterns/index_pattern { "override": false, "refresh_fields": true, - "make_default": true, "index_pattern": { "title": "hello" } @@ -221,13 +218,13 @@ POST /api/index_patterns/index_pattern } ``` -When you are updating fields, you can skip field refresh using `refresh_fields` flag. -`refresh_fields` defaults to `true`. +- `refresh_fields` — if set to `true` reloads index pattern fields after + the index pattern is stored. Defaults to `false`. ``` POST /api/index_patterns/index_pattern { - "refresh_fields": false, + "refresh_fields": true, "index_pattern": { "fields": {} } @@ -299,12 +296,13 @@ POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fiel } ``` -You can skip field refresh using `refresh_fields` flag. `refresh_fields` defaults to `true`. +- `refresh_fields` — if set to `true` reloads index pattern fields after + the index pattern is stored. Defaults to `false`. ``` POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fields { - "refresh_fields": false, + "refresh_fields": true, "fields": {} } ``` From 9b18f3a04b593175afbd4b822e1d893b941340a8 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 17:36:39 +0100 Subject: [PATCH 74/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20fix=20TypeScript?= =?UTF-8?q?=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/scripted_fields/create_scripted_field.ts | 6 +++++- .../routes/scripted_fields/put_scripted_field.ts | 6 +++++- .../server/index_patterns/routes/update_index_pattern.ts | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 7222c71f48d90..7067ca1536bfe 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -64,7 +64,11 @@ export const registerCreateScriptedFieldRoute = (router: IRouter) => { throw new Error(`Field [name = ${field.name}] already exists.`); } - indexPattern.fields.add(field); + indexPattern.fields.add({ + ...field, + aggregatable: true, + searchable: true, + }); await ip.updateSavedObject(indexPattern); if (refresh_fields) { diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index 51c2ccda70245..f4c51d569b7ff 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -65,7 +65,11 @@ export const registerPutScriptedFieldRoute = (router: IRouter) => { indexPattern.fields.remove(oldFieldObject); } - indexPattern.fields.add(field); + indexPattern.fields.add({ + ...field, + aggregatable: true, + searchable: true, + }); await ip.updateSavedObject(indexPattern); if (refresh_fields) { diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index d6c0f31172217..561375ec89cbb 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -124,7 +124,13 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { if (fields !== undefined) { changeCount++; doRefreshFields = true; - indexPattern.fields.replaceAll(Object.values(fields || {})); + indexPattern.fields.replaceAll( + Object.values(fields || {}).map((field) => ({ + ...field, + aggregatable: true, + searchable: true, + })) + ); } if (changeCount < 1) { From bc3360ed8e0d5474ca458fe14fff597dd59ade48 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 17:44:08 +0100 Subject: [PATCH 75/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20try=20fixing=20fun?= =?UTF-8?q?ctional=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns_service.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/plugins/data/server/index_patterns/index_patterns_service.ts b/src/plugins/data/server/index_patterns/index_patterns_service.ts index 7a40a8697a740..69fd83faef892 100644 --- a/src/plugins/data/server/index_patterns/index_patterns_service.ts +++ b/src/plugins/data/server/index_patterns/index_patterns_service.ts @@ -47,9 +47,9 @@ export interface IndexPatternsServiceStartDeps { } export class IndexPatternsService implements Plugin { - #uiSettings?: CoreStart['uiSettings']; - #fieldFormats?: FieldFormatsStart; - #logger?: Logger; + private uiSettings?: CoreStart['uiSettings']; + private fieldFormats?: FieldFormatsStart; + private logger?: Logger; public setup(core: CoreSetup) { core.savedObjects.registerType(indexPatternSavedObjectType); @@ -59,9 +59,9 @@ export class IndexPatternsService implements Plugin { - this.#logger!.error(error); + this.logger!.error(error); }, onNotification: ({ title, text }) => { - this.#logger!.warn(`${title} : ${text}`); + this.logger!.warn(`${title} : ${text}`); }, }); } From 319523ccadec3e8eac178f7abe574f492112c244 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 1 Dec 2020 18:09:31 +0100 Subject: [PATCH 76/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20aut?= =?UTF-8?q?o-generated=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ins-data-server.indexpatternsservice.__private_.md | 11 ----------- ...plugin-plugins-data-server.indexpatternsservice.md | 6 ------ src/plugins/data/server/server.api.md | 4 +--- 3 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md deleted file mode 100644 index c909f5f961e1a..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) > ["\#private"](./kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md) - -## IndexPatternsService."\#private" property - -Signature: - -```typescript -#private; -``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md index d819f375e1f43..ea0ef7ef44f27 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md @@ -10,12 +10,6 @@ export declare class IndexPatternsService implements Plugin ``` -## Properties - -| Property | Modifiers | Type | Description | -| --- | --- | --- | --- | -| ["\#private"](./kibana-plugin-plugins-data-server.indexpatternsservice.__private_.md) | | | | - ## Methods | Method | Modifiers | Description | diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index d356b6bf48646..d5aa76d01cf8b 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -739,8 +739,6 @@ export class IndexPatternsFetcher { // // @public (undocumented) export class IndexPatternsService implements Plugin_3 { - // (undocumented) - #private; // (undocumented) createIndexPatternsService(savedObjectsClient: SavedObjectsClientContract_2, elasticsearchClient: ElasticsearchClient_2): Promise; // (undocumented) @@ -751,7 +749,7 @@ export class IndexPatternsService implements Plugin_3, elasticsearchClient: ElasticsearchClient_2) => Promise; }; -} + } // Warning: (ae-missing-release-tag) "ISearchOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // From 10c6d90038d82a5aa4153413ce5a97b9f5ccaccc Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 2 Dec 2020 14:48:15 +0100 Subject: [PATCH 77/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20check=20if=20this?= =?UTF-8?q?=20fixes=20security=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/index_patterns/index_patterns/index_patterns.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 88801f89a475b..ce7b3c9dd3ae0 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -217,7 +217,7 @@ export class IndexPatternsService { */ getFieldsForWildcard = async (options: GetFieldsOptions) => { const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS); - return await this.apiClient.getFieldsForWildcard({ + return this.apiClient.getFieldsForWildcard({ pattern: options.pattern, metaFields, type: options.type, @@ -233,7 +233,7 @@ export class IndexPatternsService { indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions ) => - await this.getFieldsForWildcard({ + this.getFieldsForWildcard({ type: indexPattern.type, rollupIndex: indexPattern?.typeMeta?.params?.rollup_index, ...options, From b990de7b25c8f2adbea3672e9789b3e68e0c7377 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 2 Dec 2020 15:06:11 +0100 Subject: [PATCH 78/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20create=20index=20pa?= =?UTF-8?q?tterns=20context=20only=20if=20user=20is=20authc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/util/assert_index_patterns_context.ts | 2 +- src/plugins/data/server/plugin.ts | 4 +++- src/plugins/data/server/types.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts b/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts index b6c7e1fb1a443..d70827bdac900 100644 --- a/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts +++ b/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts @@ -21,7 +21,7 @@ import { RequestHandler, RequestHandlerContext, RouteMethod } from '../../../../ import { IndexPatternsRouteContext, IndexPatternsRequestHandler } from '../../../types'; const isTagsRouteContext = (context: RequestHandlerContext): context is IndexPatternsRouteContext => - !!context.indexPatterns; + !!context.indexPatterns && !!context.indexPatterns.indexPatterns; /** * This higher order request handler makes sure that `ctx.indexPatterns` diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index ec84510056b70..735470b601944 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -98,7 +98,9 @@ export class DataServerPlugin this.indexPatterns.setup(core); core.http.registerRouteHandlerContext( 'indexPatterns', - async (context, req, res): Promise => { + async (context, req): Promise> => { + if (!req.auth.isAuthenticated) return {}; + const savedObjectsClient = context.core.savedObjects.client; const elasticsearchClient = context.core.elasticsearch.client.asCurrentUser; const indexPatterns = await this.indexPatterns.createIndexPatternsService( diff --git a/src/plugins/data/server/types.ts b/src/plugins/data/server/types.ts index ee8e9d28b3f05..4e138efb0ce4e 100644 --- a/src/plugins/data/server/types.ts +++ b/src/plugins/data/server/types.ts @@ -32,7 +32,7 @@ export interface IndexPatternsRequestHandlerContext { declare module 'src/core/server' { interface RequestHandlerContext { - indexPatterns?: IndexPatternsRequestHandlerContext; + indexPatterns?: Partial; } } From 9dbe3f9f7939ab9e44aa23ee56842428cbca0b59 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 3 Dec 2020 09:39:19 +0100 Subject: [PATCH 79/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20assert=20on=20index?= =?UTF-8?q?=20patterns=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes/create_index_pattern.ts | 2 +- .../data/server/index_patterns/routes/delete_index_pattern.ts | 2 +- .../data/server/index_patterns/routes/fields/update_fields.ts | 2 +- .../data/server/index_patterns/routes/get_index_pattern.ts | 2 +- .../routes/scripted_fields/create_scripted_field.ts | 2 +- .../routes/scripted_fields/delete_scripted_field.ts | 2 +- .../index_patterns/routes/scripted_fields/get_scripted_field.ts | 2 +- .../index_patterns/routes/scripted_fields/put_scripted_field.ts | 2 +- .../routes/scripted_fields/update_scripted_field.ts | 2 +- .../data/server/index_patterns/routes/update_index_pattern.ts | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index b23c8d37fbf27..9bda577866e90 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -67,7 +67,7 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const body = req.body; const indexPattern = await ip.createAndSave( body.index_pattern as IndexPatternSpec, diff --git a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts index 33562c25e54c0..5811189839140 100644 --- a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts @@ -41,7 +41,7 @@ export const registerDeleteIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; await ip.delete(id); diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts index 4ab25873352ec..5aed2cbfc09b3 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts @@ -63,7 +63,7 @@ export const registerUpdateFieldsRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts index 6de77d773a91f..3157813d5a902 100644 --- a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts @@ -41,7 +41,7 @@ export const registerGetIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const indexPattern = await ip.get(id); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 7067ca1536bfe..6f84f2d729c13 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -46,7 +46,7 @@ export const registerCreateScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts index 4ae0e7a10c68f..f9138742c5ff6 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts @@ -46,7 +46,7 @@ export const registerDeleteScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const name = req.params.name; diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts index 3ca772af001d4..0d8612b1a68a7 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts @@ -46,7 +46,7 @@ export const registerGetScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const name = req.params.name; diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index f4c51d569b7ff..92c37a0fd36ae 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -46,7 +46,7 @@ export const registerPutScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index 6886d3e4f010f..b7e3b666ace81 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -67,7 +67,7 @@ export const registerUpdateScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const name = req.params.name; const { diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 561375ec89cbb..d6bfbe65889e9 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -63,7 +63,7 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns; + const ip = ctx.indexPatterns.indexPatterns!; const id = req.params.id; const indexPattern = await ip.get(id); From 9cc081703b0296f7af7f272f1ed0f3f711e05595 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 3 Dec 2020 10:31:17 +0100 Subject: [PATCH 80/93] =?UTF-8?q?test:=20=F0=9F=92=8D=20try=20fixing=20int?= =?UTF-8?q?egration=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/server/plugin.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 735470b601944..996795712baee 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -98,11 +98,10 @@ export class DataServerPlugin this.indexPatterns.setup(core); core.http.registerRouteHandlerContext( 'indexPatterns', - async (context, req): Promise> => { - if (!req.auth.isAuthenticated) return {}; - + async (context): Promise> => { const savedObjectsClient = context.core.savedObjects.client; const elasticsearchClient = context.core.elasticsearch.client.asCurrentUser; + const indexPatterns = await this.indexPatterns.createIndexPatternsService( savedObjectsClient, elasticsearchClient From cce1c9adfcd4592c13846f2e00972e1577891b85 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 3 Dec 2020 12:44:46 +0100 Subject: [PATCH 81/93] =?UTF-8?q?fix:=20=F0=9F=90=9B=20try=20fixing=20inte?= =?UTF-8?q?gration=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/server/plugin.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 996795712baee..9b19245404a3e 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -99,17 +99,21 @@ export class DataServerPlugin core.http.registerRouteHandlerContext( 'indexPatterns', async (context): Promise> => { - const savedObjectsClient = context.core.savedObjects.client; - const elasticsearchClient = context.core.elasticsearch.client.asCurrentUser; - - const indexPatterns = await this.indexPatterns.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - - return { - indexPatterns, - }; + try { + const savedObjectsClient = context.core.savedObjects.client; + const elasticsearchClient = context.core.elasticsearch.client.asCurrentUser; + + const indexPatterns = await this.indexPatterns.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + + return { + indexPatterns, + }; + } catch { + return {}; + } } ); From 1df432038ba8f19d877edde6eda733ed8ea814e8 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 4 Dec 2020 14:35:57 +0100 Subject: [PATCH 82/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20auto-gen?= =?UTF-8?q?erated=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ibana-plugin-plugins-data-server.indexpatternsservice.md | 1 + src/plugins/data/server/server.api.md | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md index 439f4ff9fa78d..f9df7c3a95c27 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md @@ -14,6 +14,7 @@ export declare class IndexPatternsService implements Plugin { + // (undocumented) + createIndexPatternsService(savedObjectsClient: SavedObjectsClientContract_2, elasticsearchClient: ElasticsearchClient_2): Promise; // Warning: (ae-forgotten-export) The symbol "DataPluginStartDependencies" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "IndexPatternsServiceSetupDeps" needs to be exported by the entry point index.d.ts // @@ -1258,8 +1260,8 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:271:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index_patterns/index_patterns_service.ts:70:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/plugin.ts:90:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index_patterns/index_patterns_service.ts:74:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/plugin.ts:91:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From 4816387c8a99c20d5cb24de2ddc4fa794c4412cd Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 4 Dec 2020 14:51:04 +0100 Subject: [PATCH 83/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20directly=20inj?= =?UTF-8?q?ect=20index=20pattern=20provider=20into=20create?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/server/index.ts | 2 +- src/plugins/data/server/index_patterns/index.ts | 2 +- .../index_patterns/index_patterns_service.ts | 4 ++-- src/plugins/data/server/index_patterns/routes.ts | 8 ++++++-- .../index_patterns/routes/create_index_pattern.ts | 15 ++++++++++++--- src/plugins/data/server/plugin.ts | 4 ++-- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index a233447cdf438..1d67b1d36b7bb 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -315,4 +315,4 @@ export const config: PluginConfigDescriptor = { schema: configSchema, }; -export type { IndexPatternsService } from './index_patterns'; +export type { IndexPatternsServiceProvider as IndexPatternsService } from './index_patterns'; diff --git a/src/plugins/data/server/index_patterns/index.ts b/src/plugins/data/server/index_patterns/index.ts index 3305b1bb9a92f..b5bcd7cf5c483 100644 --- a/src/plugins/data/server/index_patterns/index.ts +++ b/src/plugins/data/server/index_patterns/index.ts @@ -24,4 +24,4 @@ export { mergeCapabilitiesWithFields, getCapabilitiesForRollupIndices, } from './fetcher'; -export { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns_service'; +export { IndexPatternsServiceProvider, IndexPatternsServiceStart } from './index_patterns_service'; diff --git a/src/plugins/data/server/index_patterns/index_patterns_service.ts b/src/plugins/data/server/index_patterns/index_patterns_service.ts index 5914738612717..0345e85761efc 100644 --- a/src/plugins/data/server/index_patterns/index_patterns_service.ts +++ b/src/plugins/data/server/index_patterns/index_patterns_service.ts @@ -53,7 +53,7 @@ export interface IndexPatternsServiceStartDeps { logger: Logger; } -export class IndexPatternsService implements Plugin { +export class IndexPatternsServiceProvider implements Plugin { private uiSettings?: CoreStart['uiSettings']; private fieldFormats?: FieldFormatsStart; private logger?: Logger; @@ -65,7 +65,7 @@ export class IndexPatternsService implements Plugin { let parsedFields: string[] = []; if (typeof metaFields === 'string') { @@ -45,7 +49,7 @@ export function registerRoutes(http: HttpServiceSetup) { const router = http.createRouter(); // Index Patterns API - registerCreateIndexPatternRoute(router); + registerCreateIndexPatternRoute(router, indexPatternsProvider); registerGetIndexPatternRoute(router); registerDeleteIndexPatternRoute(router); registerUpdateIndexPatternRoute(router); diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 9bda577866e90..c0a468384a3f0 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -23,6 +23,7 @@ import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; +import type { IndexPatternsServiceProvider } from '../index_patterns_service'; const indexPatternSpecSchema = schema.object({ title: schema.string(), @@ -52,7 +53,10 @@ const indexPatternSpecSchema = schema.object({ ), }); -export const registerCreateIndexPatternRoute = (router: IRouter) => { +export const registerCreateIndexPatternRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.post( { path: '/api/index_patterns/index_pattern', @@ -67,9 +71,14 @@ export const registerCreateIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const body = req.body; - const indexPattern = await ip.createAndSave( + const indexPattern = await indexPatternsService.createAndSave( body.index_pattern as IndexPatternSpec, body.override, !body.refresh_fields diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 937abb0402134..5293ca1ac65e9 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -21,7 +21,7 @@ import { CoreSetup, CoreStart, Logger, Plugin, PluginInitializerContext } from ' import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; import { BfetchServerSetup } from 'src/plugins/bfetch/server'; import { ConfigSchema } from '../config'; -import { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns'; +import { IndexPatternsServiceProvider, IndexPatternsServiceStart } from './index_patterns'; import { ISearchSetup, ISearchStart, SearchEnhancements } from './search'; import { SearchService } from './search/search_service'; import { QueryService } from './query/query_service'; @@ -73,7 +73,7 @@ export class DataServerPlugin private readonly scriptsService: ScriptsService; private readonly kqlTelemetryService: KqlTelemetryService; private readonly autocompleteService: AutocompleteService; - private readonly indexPatterns = new IndexPatternsService(); + private readonly indexPatterns = new IndexPatternsServiceProvider(); private readonly fieldFormats = new FieldFormatsService(); private readonly queryService = new QueryService(); private readonly logger: Logger; From 2d9e321cbaa892e1b1f9676fbfe7f0dafb9f65cd Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 4 Dec 2020 16:02:25 +0100 Subject: [PATCH 84/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20create=20index?= =?UTF-8?q?=20pattern=20service=20directly=20in=20each=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes.ts | 18 ++-- .../routes/delete_index_pattern.ts | 15 ++- .../routes/fields/update_fields.ts | 19 +++- .../routes/get_index_pattern.ts | 15 ++- .../scripted_fields/create_scripted_field.ts | 19 +++- .../scripted_fields/delete_scripted_field.ts | 17 +++- .../scripted_fields/get_scripted_field.ts | 15 ++- .../scripted_fields/put_scripted_field.ts | 19 +++- .../scripted_fields/update_scripted_field.ts | 92 ++++++++++--------- .../routes/update_index_pattern.ts | 19 +++- 10 files changed, 163 insertions(+), 85 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 6c7b1bf1c9b0c..d0e6789d96ccf 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -50,19 +50,19 @@ export function registerRoutes( // Index Patterns API registerCreateIndexPatternRoute(router, indexPatternsProvider); - registerGetIndexPatternRoute(router); - registerDeleteIndexPatternRoute(router); - registerUpdateIndexPatternRoute(router); + registerGetIndexPatternRoute(router, indexPatternsProvider); + registerDeleteIndexPatternRoute(router, indexPatternsProvider); + registerUpdateIndexPatternRoute(router, indexPatternsProvider); // Fields API - registerUpdateFieldsRoute(router); + registerUpdateFieldsRoute(router, indexPatternsProvider); // Scripted Field API - registerCreateScriptedFieldRoute(router); - registerPutScriptedFieldRoute(router); - registerGetScriptedFieldRoute(router); - registerDeleteScriptedFieldRoute(router); - registerUpdateScriptedFieldRoute(router); + registerCreateScriptedFieldRoute(router, indexPatternsProvider); + registerPutScriptedFieldRoute(router, indexPatternsProvider); + registerGetScriptedFieldRoute(router, indexPatternsProvider); + registerDeleteScriptedFieldRoute(router, indexPatternsProvider); + registerUpdateScriptedFieldRoute(router, indexPatternsProvider); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts index 5811189839140..9e25d754f8948 100644 --- a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts @@ -21,8 +21,12 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; +import type { IndexPatternsServiceProvider } from '../index_patterns_service'; -export const registerDeleteIndexPatternRoute = (router: IRouter) => { +export const registerDeleteIndexPatternRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.delete( { path: '/api/index_patterns/index_pattern/{id}', @@ -41,10 +45,15 @@ export const registerDeleteIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; - await ip.delete(id); + await indexPatternsService.delete(id); return res.ok({ headers: { diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts index 5aed2cbfc09b3..9b0d1ac95c78f 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts @@ -22,8 +22,12 @@ import { IRouter } from '../../../../../../core/server'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import { serializedFieldFormatSchema } from '../util/schemas'; +import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; -export const registerUpdateFieldsRoute = (router: IRouter) => { +export const registerUpdateFieldsRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.post( { path: '/api/index_patterns/index_pattern/{id}/fields', @@ -63,7 +67,12 @@ export const registerUpdateFieldsRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -76,7 +85,7 @@ export const registerUpdateFieldsRoute = (router: IRouter) => { throw new Error('No fields provided.'); } - const indexPattern = await ip.get(id); + const indexPattern = await indexPatternsService.get(id); let changeCount = 0; for (const fieldName of fieldNames) { @@ -106,10 +115,10 @@ export const registerUpdateFieldsRoute = (router: IRouter) => { throw new Error('Change set is empty.'); } - await ip.updateSavedObject(indexPattern); + await indexPatternsService.updateSavedObject(indexPattern); if (refresh_fields) { - await ip.refreshFields(indexPattern); + await indexPatternsService.refreshFields(indexPattern); } return res.ok({ diff --git a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts index 3157813d5a902..323dd0512bb59 100644 --- a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts @@ -21,8 +21,12 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; +import type { IndexPatternsServiceProvider } from '../index_patterns_service'; -export const registerGetIndexPatternRoute = (router: IRouter) => { +export const registerGetIndexPatternRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.get( { path: '/api/index_patterns/index_pattern/{id}', @@ -41,9 +45,14 @@ export const registerGetIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; - const indexPattern = await ip.get(id); + const indexPattern = await indexPatternsService.get(id); return res.ok({ headers: { diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 6f84f2d729c13..49020a8ae1e98 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -22,8 +22,12 @@ import { IRouter } from '../../../../../../core/server'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; +import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; -export const registerCreateScriptedFieldRoute = (router: IRouter) => { +export const registerCreateScriptedFieldRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.post( { path: '/api/index_patterns/index_pattern/{id}/scripted_field', @@ -46,7 +50,12 @@ export const registerCreateScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -58,7 +67,7 @@ export const registerCreateScriptedFieldRoute = (router: IRouter) => { throw new Error('Only scripted fields can be created.'); } - const indexPattern = await ip.get(id); + const indexPattern = await indexPatternsService.get(id); if (indexPattern.fields.getByName(field.name)) { throw new Error(`Field [name = ${field.name}] already exists.`); @@ -70,9 +79,9 @@ export const registerCreateScriptedFieldRoute = (router: IRouter) => { searchable: true, }); - await ip.updateSavedObject(indexPattern); + await indexPatternsService.updateSavedObject(indexPattern); if (refresh_fields) { - await ip.refreshFields(indexPattern); + await indexPatternsService.refreshFields(indexPattern); } const fieldObject = indexPattern.fields.getByName(field.name); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts index f9138742c5ff6..a5951bf69b5da 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts @@ -22,8 +22,12 @@ import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; +import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; -export const registerDeleteScriptedFieldRoute = (router: IRouter) => { +export const registerDeleteScriptedFieldRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.delete( { path: '/api/index_patterns/index_pattern/{id}/scripted_field/{name}', @@ -46,11 +50,16 @@ export const registerDeleteScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; const name = req.params.name; - const indexPattern = await ip.get(id); + const indexPattern = await indexPatternsService.get(id); const field = indexPattern.fields.getByName(name); if (!field) { @@ -63,7 +72,7 @@ export const registerDeleteScriptedFieldRoute = (router: IRouter) => { indexPattern.fields.remove(field); - await ip.updateSavedObject(indexPattern); + await indexPatternsService.updateSavedObject(indexPattern); return res.ok({ headers: { diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts index 0d8612b1a68a7..194ae78294270 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts @@ -22,8 +22,12 @@ import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; +import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; -export const registerGetScriptedFieldRoute = (router: IRouter) => { +export const registerGetScriptedFieldRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.get( { path: '/api/index_patterns/index_pattern/{id}/scripted_field/{name}', @@ -46,11 +50,16 @@ export const registerGetScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; const name = req.params.name; - const indexPattern = await ip.get(id); + const indexPattern = await indexPatternsService.get(id); const field = indexPattern.fields.getByName(name); if (!field) { diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index 92c37a0fd36ae..866ed3747afcc 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -22,8 +22,12 @@ import { IRouter } from '../../../../../../core/server'; import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; +import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; -export const registerPutScriptedFieldRoute = (router: IRouter) => { +export const registerPutScriptedFieldRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.put( { path: '/api/index_patterns/index_pattern/{id}/scripted_field', @@ -46,7 +50,12 @@ export const registerPutScriptedFieldRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; const { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -58,7 +67,7 @@ export const registerPutScriptedFieldRoute = (router: IRouter) => { throw new Error('Only scripted fields can be put.'); } - const indexPattern = await ip.get(id); + const indexPattern = await indexPatternsService.get(id); const oldFieldObject = indexPattern.fields.getByName(field.name); if (!!oldFieldObject) { @@ -71,9 +80,9 @@ export const registerPutScriptedFieldRoute = (router: IRouter) => { searchable: true, }); - await ip.updateSavedObject(indexPattern); + await indexPatternsService.updateSavedObject(indexPattern); if (refresh_fields) { - await ip.refreshFields(indexPattern); + await indexPatternsService.refreshFields(indexPattern); } const fieldObject = indexPattern.fields.getByName(field.name); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index b7e3b666ace81..1c258758dbda8 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -21,11 +21,14 @@ import { schema } from '@kbn/config-schema'; import { FieldSpec } from 'src/plugins/data/common'; import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; -import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchemaFields } from '../util/schemas'; +import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; -export const registerUpdateScriptedFieldRoute = (router: IRouter) => { +export const registerUpdateScriptedFieldRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.post( { path: '/api/index_patterns/index_pattern/{id}/scripted_field/{name}', @@ -65,56 +68,59 @@ export const registerUpdateScriptedFieldRoute = (router: IRouter) => { }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; - const id = req.params.id; - const name = req.params.name; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - } = req.body; + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + const name = req.params.name; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + refresh_fields = true, + } = req.body; - const field = ({ ...req.body.field, name } as unknown) as FieldSpec; + const field = ({ ...req.body.field, name } as unknown) as FieldSpec; - const indexPattern = await ip.get(id); - let fieldObject = indexPattern.fields.getByName(field.name); + const indexPattern = await indexPatternsService.get(id); + let fieldObject = indexPattern.fields.getByName(field.name); - if (!fieldObject) { - throw new ErrorIndexPatternFieldNotFound(id, name); - } + if (!fieldObject) { + throw new ErrorIndexPatternFieldNotFound(id, name); + } - if (!fieldObject.scripted) { - throw new Error('Only scripted fields can be updated.'); - } + if (!fieldObject.scripted) { + throw new Error('Only scripted fields can be updated.'); + } - const oldSpec = fieldObject.toSpec(); + const oldSpec = fieldObject.toSpec(); - indexPattern.fields.remove(fieldObject); - indexPattern.fields.add({ - ...oldSpec, - ...field, - }); + indexPattern.fields.remove(fieldObject); + indexPattern.fields.add({ + ...oldSpec, + ...field, + }); - await ip.updateSavedObject(indexPattern); - if (refresh_fields) { - await ip.refreshFields(indexPattern); - } + await indexPatternsService.updateSavedObject(indexPattern); + if (refresh_fields) { + await indexPatternsService.refreshFields(indexPattern); + } - fieldObject = indexPattern.fields.getByName(field.name); - if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); + fieldObject = indexPattern.fields.getByName(field.name); + if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - field: fieldObject.toSpec(), - index_pattern: indexPattern.toSpec(), - }), - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: fieldObject.toSpec(), + index_pattern: indexPattern.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index d6bfbe65889e9..95d3e7b9406ed 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -22,6 +22,7 @@ import { IRouter } from '../../../../../core/server'; import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; +import type { IndexPatternsServiceProvider } from '../index_patterns_service'; const indexPatternUpdateSchema = schema.object({ title: schema.maybe(schema.string()), @@ -40,7 +41,10 @@ const indexPatternUpdateSchema = schema.object({ fields: schema.maybe(schema.recordOf(schema.string(), fieldSpecSchema)), }); -export const registerUpdateIndexPatternRoute = (router: IRouter) => { +export const registerUpdateIndexPatternRoute = ( + router: IRouter, + indexPatternsProvider: IndexPatternsServiceProvider +) => { router.post( { path: '/api/index_patterns/index_pattern/{id}', @@ -63,10 +67,15 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { router.handleLegacyErrors( handleErrors( assertIndexPatternsContext(async (ctx, req, res) => { - const ip = ctx.indexPatterns.indexPatterns!; + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); const id = req.params.id; - const indexPattern = await ip.get(id); + const indexPattern = await indexPatternsService.get(id); const { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -137,10 +146,10 @@ export const registerUpdateIndexPatternRoute = (router: IRouter) => { throw new Error('Index pattern change set is empty.'); } - await ip.updateSavedObject(indexPattern); + await indexPatternsService.updateSavedObject(indexPattern); if (doRefreshFields && refresh_fields) { - await ip.refreshFields(indexPattern); + await indexPatternsService.refreshFields(indexPattern); } return res.ok({ From b6d49f89354097d1e7d89b3775d18b3e14e04d7b Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 4 Dec 2020 16:14:25 +0100 Subject: [PATCH 85/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20remove=20index?= =?UTF-8?q?=20pattern=20route=20context=20provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/create_index_pattern.ts | 47 ++--- .../routes/delete_index_pattern.ts | 33 ++- .../routes/fields/update_fields.ts | 107 +++++----- .../routes/get_index_pattern.ts | 39 ++-- .../scripted_fields/create_scripted_field.ts | 85 ++++---- .../scripted_fields/delete_scripted_field.ts | 53 +++-- .../scripted_fields/get_scripted_field.ts | 55 +++-- .../scripted_fields/put_scripted_field.ts | 87 ++++---- .../routes/update_index_pattern.ts | 191 +++++++++--------- .../util/assert_index_patterns_context.ts | 36 ---- src/plugins/data/server/plugin.ts | 21 -- src/plugins/data/server/types.ts | 52 ----- 12 files changed, 335 insertions(+), 471 deletions(-) delete mode 100644 src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts delete mode 100644 src/plugins/data/server/types.ts diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index c0a468384a3f0..147fcd14f1472 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -20,7 +20,6 @@ import { schema } from '@kbn/config-schema'; import { IndexPatternSpec } from 'src/plugins/data/common'; import { IRouter } from '../../../../../core/server'; -import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; import type { IndexPatternsServiceProvider } from '../index_patterns_service'; @@ -69,31 +68,29 @@ export const registerCreateIndexPatternRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const body = req.body; - const indexPattern = await indexPatternsService.createAndSave( - body.index_pattern as IndexPatternSpec, - body.override, - !body.refresh_fields - ); + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const body = req.body; + const indexPattern = await indexPatternsService.createAndSave( + body.index_pattern as IndexPatternSpec, + body.override, + !body.refresh_fields + ); - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - index_pattern: indexPattern.toSpec(), - }), - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts index 9e25d754f8948..a9a3d10919d2d 100644 --- a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts @@ -19,7 +19,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; -import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; import type { IndexPatternsServiceProvider } from '../index_patterns_service'; @@ -43,25 +42,23 @@ export const registerDeleteIndexPatternRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const id = req.params.id; + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; - await indexPatternsService.delete(id); + await indexPatternsService.delete(id); - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts index 9b0d1ac95c78f..491254356c019 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts @@ -19,7 +19,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; -import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import { serializedFieldFormatSchema } from '../util/schemas'; import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; @@ -65,72 +64,70 @@ export const registerUpdateFieldsRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const id = req.params.id; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - fields, - } = req.body; - const fieldNames = Object.keys(fields); + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + refresh_fields = true, + fields, + } = req.body; + const fieldNames = Object.keys(fields); - if (fieldNames.length < 1) { - throw new Error('No fields provided.'); - } + if (fieldNames.length < 1) { + throw new Error('No fields provided.'); + } - const indexPattern = await indexPatternsService.get(id); + const indexPattern = await indexPatternsService.get(id); - let changeCount = 0; - for (const fieldName of fieldNames) { - const field = fields[fieldName]; + let changeCount = 0; + for (const fieldName of fieldNames) { + const field = fields[fieldName]; - if (field.customLabel !== undefined) { - changeCount++; - indexPattern.setFieldCustomLabel(fieldName, field.customLabel); - } + if (field.customLabel !== undefined) { + changeCount++; + indexPattern.setFieldCustomLabel(fieldName, field.customLabel); + } - if (field.count !== undefined) { - changeCount++; - indexPattern.setFieldCount(fieldName, field.count); - } + if (field.count !== undefined) { + changeCount++; + indexPattern.setFieldCount(fieldName, field.count); + } - if (field.format !== undefined) { - changeCount++; - if (field.format) { - indexPattern.setFieldFormat(fieldName, field.format); - } else { - indexPattern.deleteFieldFormat(fieldName); - } + if (field.format !== undefined) { + changeCount++; + if (field.format) { + indexPattern.setFieldFormat(fieldName, field.format); + } else { + indexPattern.deleteFieldFormat(fieldName); } } + } - if (changeCount < 1) { - throw new Error('Change set is empty.'); - } + if (changeCount < 1) { + throw new Error('Change set is empty.'); + } - await indexPatternsService.updateSavedObject(indexPattern); + await indexPatternsService.updateSavedObject(indexPattern); - if (refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } + if (refresh_fields) { + await indexPatternsService.refreshFields(indexPattern); + } - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - index_pattern: indexPattern.toSpec(), - }), - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts index 323dd0512bb59..19c95b378257a 100644 --- a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts @@ -19,7 +19,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; -import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; import type { IndexPatternsServiceProvider } from '../index_patterns_service'; @@ -43,27 +42,25 @@ export const registerGetIndexPatternRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const id = req.params.id; - const indexPattern = await indexPatternsService.get(id); + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + const indexPattern = await indexPatternsService.get(id); - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - index_pattern: indexPattern.toSpec(), - }), - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 49020a8ae1e98..07ac3c110cf2e 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -19,7 +19,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; -import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; @@ -48,56 +47,54 @@ export const registerCreateScriptedFieldRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const id = req.params.id; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - field, - } = req.body; + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + refresh_fields = true, + field, + } = req.body; - if (!field.scripted) { - throw new Error('Only scripted fields can be created.'); - } + if (!field.scripted) { + throw new Error('Only scripted fields can be created.'); + } - const indexPattern = await indexPatternsService.get(id); + const indexPattern = await indexPatternsService.get(id); - if (indexPattern.fields.getByName(field.name)) { - throw new Error(`Field [name = ${field.name}] already exists.`); - } + if (indexPattern.fields.getByName(field.name)) { + throw new Error(`Field [name = ${field.name}] already exists.`); + } - indexPattern.fields.add({ - ...field, - aggregatable: true, - searchable: true, - }); + indexPattern.fields.add({ + ...field, + aggregatable: true, + searchable: true, + }); - await indexPatternsService.updateSavedObject(indexPattern); - if (refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } + await indexPatternsService.updateSavedObject(indexPattern); + if (refresh_fields) { + await indexPatternsService.refreshFields(indexPattern); + } - const fieldObject = indexPattern.fields.getByName(field.name); - if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); + const fieldObject = indexPattern.fields.getByName(field.name); + if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - field: fieldObject.toSpec(), - index_pattern: indexPattern.toSpec(), - }), - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: fieldObject.toSpec(), + index_pattern: indexPattern.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts index a5951bf69b5da..92ddddb4ae93d 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts @@ -20,7 +20,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; -import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; @@ -48,39 +47,37 @@ export const registerDeleteScriptedFieldRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const id = req.params.id; - const name = req.params.name; + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + const name = req.params.name; - const indexPattern = await indexPatternsService.get(id); - const field = indexPattern.fields.getByName(name); + const indexPattern = await indexPatternsService.get(id); + const field = indexPattern.fields.getByName(name); - if (!field) { - throw new ErrorIndexPatternFieldNotFound(id, name); - } + if (!field) { + throw new ErrorIndexPatternFieldNotFound(id, name); + } - if (!field.scripted) { - throw new Error('Only scripted fields can be deleted.'); - } + if (!field.scripted) { + throw new Error('Only scripted fields can be deleted.'); + } - indexPattern.fields.remove(field); + indexPattern.fields.remove(field); - await indexPatternsService.updateSavedObject(indexPattern); + await indexPatternsService.updateSavedObject(indexPattern); - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts index 194ae78294270..551f244a6d1a4 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts @@ -20,7 +20,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; -import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; @@ -48,38 +47,36 @@ export const registerGetScriptedFieldRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const id = req.params.id; - const name = req.params.name; + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + const name = req.params.name; - const indexPattern = await indexPatternsService.get(id); - const field = indexPattern.fields.getByName(name); + const indexPattern = await indexPatternsService.get(id); + const field = indexPattern.fields.getByName(name); - if (!field) { - throw new ErrorIndexPatternFieldNotFound(id, name); - } + if (!field) { + throw new ErrorIndexPatternFieldNotFound(id, name); + } - if (!field.scripted) { - throw new Error('Only scripted fields can be retrieved.'); - } + if (!field.scripted) { + throw new Error('Only scripted fields can be retrieved.'); + } - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - field: field.toSpec(), - }), - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: field.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index 866ed3747afcc..e409897365772 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -19,7 +19,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../../core/server'; -import { assertIndexPatternsContext } from '../util/assert_index_patterns_context'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; @@ -48,57 +47,55 @@ export const registerPutScriptedFieldRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - const id = req.params.id; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - field, - } = req.body; + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + refresh_fields = true, + field, + } = req.body; - if (!field.scripted) { - throw new Error('Only scripted fields can be put.'); - } + if (!field.scripted) { + throw new Error('Only scripted fields can be put.'); + } - const indexPattern = await indexPatternsService.get(id); + const indexPattern = await indexPatternsService.get(id); - const oldFieldObject = indexPattern.fields.getByName(field.name); - if (!!oldFieldObject) { - indexPattern.fields.remove(oldFieldObject); - } + const oldFieldObject = indexPattern.fields.getByName(field.name); + if (!!oldFieldObject) { + indexPattern.fields.remove(oldFieldObject); + } - indexPattern.fields.add({ - ...field, - aggregatable: true, - searchable: true, - }); + indexPattern.fields.add({ + ...field, + aggregatable: true, + searchable: true, + }); - await indexPatternsService.updateSavedObject(indexPattern); - if (refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } + await indexPatternsService.updateSavedObject(indexPattern); + if (refresh_fields) { + await indexPatternsService.refreshFields(indexPattern); + } - const fieldObject = indexPattern.fields.getByName(field.name); - if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); + const fieldObject = indexPattern.fields.getByName(field.name); + if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - field: fieldObject.toSpec(), - index_pattern: indexPattern.toSpec(), - }), - }); - }) - ) + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + field: fieldObject.toSpec(), + index_pattern: indexPattern.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 95d3e7b9406ed..6d6486ec90314 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -19,7 +19,6 @@ import { schema } from '@kbn/config-schema'; import { IRouter } from '../../../../../core/server'; -import { assertIndexPatternsContext } from './util/assert_index_patterns_context'; import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; import type { IndexPatternsServiceProvider } from '../index_patterns_service'; @@ -65,103 +64,101 @@ export const registerUpdateIndexPatternRoute = ( }, }, router.handleLegacyErrors( - handleErrors( - assertIndexPatternsContext(async (ctx, req, res) => { - const savedObjectsClient = ctx.core.savedObjects.client; - const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient + handleErrors(async (ctx, req, res) => { + const savedObjectsClient = ctx.core.savedObjects.client; + const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; + const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + savedObjectsClient, + elasticsearchClient + ); + const id = req.params.id; + + const indexPattern = await indexPatternsService.get(id); + + const { + // eslint-disable-next-line @typescript-eslint/naming-convention + refresh_fields = true, + index_pattern: { + title, + timeFieldName, + intervalName, + sourceFilters, + fieldFormats, + type, + typeMeta, + fields, + }, + } = req.body; + + let changeCount = 0; + let doRefreshFields = false; + + if (title !== undefined && title !== indexPattern.title) { + changeCount++; + indexPattern.title = title; + } + + if (timeFieldName !== undefined && timeFieldName !== indexPattern.timeFieldName) { + changeCount++; + indexPattern.timeFieldName = timeFieldName; + } + + if (intervalName !== undefined && intervalName !== indexPattern.intervalName) { + changeCount++; + indexPattern.intervalName = intervalName; + } + + if (sourceFilters !== undefined) { + changeCount++; + indexPattern.sourceFilters = sourceFilters; + } + + if (fieldFormats !== undefined) { + changeCount++; + indexPattern.fieldFormatMap = fieldFormats; + } + + if (type !== undefined) { + changeCount++; + indexPattern.type = type; + } + + if (typeMeta !== undefined) { + changeCount++; + indexPattern.typeMeta = typeMeta; + } + + if (fields !== undefined) { + changeCount++; + doRefreshFields = true; + indexPattern.fields.replaceAll( + Object.values(fields || {}).map((field) => ({ + ...field, + aggregatable: true, + searchable: true, + })) ); - const id = req.params.id; - - const indexPattern = await indexPatternsService.get(id); - - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - index_pattern: { - title, - timeFieldName, - intervalName, - sourceFilters, - fieldFormats, - type, - typeMeta, - fields, - }, - } = req.body; - - let changeCount = 0; - let doRefreshFields = false; - - if (title !== undefined && title !== indexPattern.title) { - changeCount++; - indexPattern.title = title; - } - - if (timeFieldName !== undefined && timeFieldName !== indexPattern.timeFieldName) { - changeCount++; - indexPattern.timeFieldName = timeFieldName; - } - - if (intervalName !== undefined && intervalName !== indexPattern.intervalName) { - changeCount++; - indexPattern.intervalName = intervalName; - } - - if (sourceFilters !== undefined) { - changeCount++; - indexPattern.sourceFilters = sourceFilters; - } - - if (fieldFormats !== undefined) { - changeCount++; - indexPattern.fieldFormatMap = fieldFormats; - } - - if (type !== undefined) { - changeCount++; - indexPattern.type = type; - } - - if (typeMeta !== undefined) { - changeCount++; - indexPattern.typeMeta = typeMeta; - } - - if (fields !== undefined) { - changeCount++; - doRefreshFields = true; - indexPattern.fields.replaceAll( - Object.values(fields || {}).map((field) => ({ - ...field, - aggregatable: true, - searchable: true, - })) - ); - } - - if (changeCount < 1) { - throw new Error('Index pattern change set is empty.'); - } - - await indexPatternsService.updateSavedObject(indexPattern); - - if (doRefreshFields && refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } - - return res.ok({ - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - index_pattern: indexPattern.toSpec(), - }), - }); - }) - ) + } + + if (changeCount < 1) { + throw new Error('Index pattern change set is empty.'); + } + + await indexPatternsService.updateSavedObject(indexPattern); + + if (doRefreshFields && refresh_fields) { + await indexPatternsService.refreshFields(indexPattern); + } + + return res.ok({ + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + index_pattern: indexPattern.toSpec(), + }), + }); + }) ) ); }; diff --git a/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts b/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts deleted file mode 100644 index d70827bdac900..0000000000000 --- a/src/plugins/data/server/index_patterns/routes/util/assert_index_patterns_context.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { RequestHandler, RequestHandlerContext, RouteMethod } from '../../../../../../core/server'; -import { IndexPatternsRouteContext, IndexPatternsRequestHandler } from '../../../types'; - -const isTagsRouteContext = (context: RequestHandlerContext): context is IndexPatternsRouteContext => - !!context.indexPatterns && !!context.indexPatterns.indexPatterns; - -/** - * This higher order request handler makes sure that `ctx.indexPatterns` - * property is present. - */ -export const assertIndexPatternsContext = ( - handler: IndexPatternsRequestHandler -): RequestHandler => (context, request, response) => { - return isTagsRouteContext(context) - ? handler(context, request, response) - : response.badRequest({ body: 'IndexPatternsRequestHandlerContext is not registered.' }); -}; diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 5293ca1ac65e9..bf2c703456493 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -94,28 +94,7 @@ export class DataServerPlugin this.queryService.setup(core); this.autocompleteService.setup(core); this.kqlTelemetryService.setup(core, { usageCollection }); - this.indexPatterns.setup(core, { expressions }); - core.http.registerRouteHandlerContext( - 'indexPatterns', - async (context): Promise> => { - try { - const savedObjectsClient = context.core.savedObjects.client; - const elasticsearchClient = context.core.elasticsearch.client.asCurrentUser; - - const indexPatterns = await this.indexPatterns.createIndexPatternsService( - savedObjectsClient, - elasticsearchClient - ); - - return { - indexPatterns, - }; - } catch { - return {}; - } - } - ); core.uiSettings.register(getUiSettings()); diff --git a/src/plugins/data/server/types.ts b/src/plugins/data/server/types.ts deleted file mode 100644 index 4e138efb0ce4e..0000000000000 --- a/src/plugins/data/server/types.ts +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { - IKibanaResponse, - KibanaRequest, - KibanaResponseFactory, - RequestHandlerContext, - RouteMethod, -} from 'src/core/server'; -import type { IndexPatternsContract } from '../common'; - -export interface IndexPatternsRequestHandlerContext { - indexPatterns: IndexPatternsContract; -} - -declare module 'src/core/server' { - interface RequestHandlerContext { - indexPatterns?: Partial; - } -} - -export type IndexPatternsRouteContext = RequestHandlerContext & - Required>; - -export type IndexPatternsRequestHandler< - P = unknown, - Q = unknown, - B = unknown, - Method extends RouteMethod = any, - ResponseFactory extends KibanaResponseFactory = KibanaResponseFactory -> = ( - context: IndexPatternsRouteContext, - request: KibanaRequest, - response: ResponseFactory -) => IKibanaResponse | Promise>; From 3155206de5218f32950b2793180d6f3c29f4c1c7 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 14:06:50 +0100 Subject: [PATCH 86/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20unused?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/server/plugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index bf2c703456493..f5efdad856e08 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -31,7 +31,6 @@ import { UsageCollectionSetup } from '../../usage_collection/server'; import { AutocompleteService } from './autocomplete'; import { FieldFormatsService, FieldFormatsSetup, FieldFormatsStart } from './field_formats'; import { getUiSettings } from './ui_settings'; -import { IndexPatternsRequestHandlerContext } from './types'; export interface DataEnhancements { search: SearchEnhancements; From fe56673364e5b85492fcc01a0fd7f428627b1fdd Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 14:25:39 +0100 Subject: [PATCH 87/93] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20refresh?= =?UTF-8?q?=5Ffields=20from=20scripted=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns.ts | 4 +-- .../routes/fields/update_fields.ts | 11 +------- .../scripted_fields/create_scripted_field.ts | 10 +------ .../scripted_fields/put_scripted_field.ts | 10 +------ .../scripted_fields/update_scripted_field.ts | 9 ------- .../create_scripted_field/errors.ts | 26 ------------------- 6 files changed, 4 insertions(+), 66 deletions(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index ce7b3c9dd3ae0..0235f748ec1e0 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -454,9 +454,7 @@ export class IndexPatternsService { } /** - * Create a new index pattern and save it right away and make the default - * index pattern. - * + * Create a new index pattern and save it right away * @param spec * @param override Overwrite if existing index pattern exists. * @param skipFetchFields Whether to skip field refresh step. diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts index 491254356c019..5fc2f742a6170 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts @@ -41,7 +41,6 @@ export const registerUpdateFieldsRoute = ( { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), fields: schema.recordOf( schema.string({ minLength: 1, @@ -72,11 +71,7 @@ export const registerUpdateFieldsRoute = ( elasticsearchClient ); const id = req.params.id; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - fields, - } = req.body; + const { fields } = req.body; const fieldNames = Object.keys(fields); if (fieldNames.length < 1) { @@ -115,10 +110,6 @@ export const registerUpdateFieldsRoute = ( await indexPatternsService.updateSavedObject(indexPattern); - if (refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } - return res.ok({ headers: { 'content-type': 'application/json', diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 07ac3c110cf2e..7c4a82fe87dcf 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -41,7 +41,6 @@ export const registerCreateScriptedFieldRoute = ( { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), field: fieldSpecSchema, }), }, @@ -55,11 +54,7 @@ export const registerCreateScriptedFieldRoute = ( elasticsearchClient ); const id = req.params.id; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - field, - } = req.body; + const { field } = req.body; if (!field.scripted) { throw new Error('Only scripted fields can be created.'); @@ -78,9 +73,6 @@ export const registerCreateScriptedFieldRoute = ( }); await indexPatternsService.updateSavedObject(indexPattern); - if (refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } const fieldObject = indexPattern.fields.getByName(field.name); if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index e409897365772..6eb311dd4d1ce 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -41,7 +41,6 @@ export const registerPutScriptedFieldRoute = ( { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), field: fieldSpecSchema, }), }, @@ -55,11 +54,7 @@ export const registerPutScriptedFieldRoute = ( elasticsearchClient ); const id = req.params.id; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - field, - } = req.body; + const { field } = req.body; if (!field.scripted) { throw new Error('Only scripted fields can be put.'); @@ -79,9 +74,6 @@ export const registerPutScriptedFieldRoute = ( }); await indexPatternsService.updateSavedObject(indexPattern); - if (refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } const fieldObject = indexPattern.fields.getByName(field.name); if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index 1c258758dbda8..490dc7a060491 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -47,7 +47,6 @@ export const registerUpdateScriptedFieldRoute = ( { unknowns: 'allow' } ), body: schema.object({ - refresh_fields: schema.maybe(schema.boolean({ defaultValue: false })), field: schema.object({ ...fieldSpecSchemaFields, @@ -77,11 +76,6 @@ export const registerUpdateScriptedFieldRoute = ( ); const id = req.params.id; const name = req.params.name; - const { - // eslint-disable-next-line @typescript-eslint/naming-convention - refresh_fields = true, - } = req.body; - const field = ({ ...req.body.field, name } as unknown) as FieldSpec; const indexPattern = await indexPatternsService.get(id); @@ -104,9 +98,6 @@ export const registerUpdateScriptedFieldRoute = ( }); await indexPatternsService.updateSavedObject(indexPattern); - if (refresh_fields) { - await indexPatternsService.refreshFields(indexPattern); - } fieldObject = indexPattern.fields.getByName(field.name); if (!fieldObject) throw new Error(`Could not create a field [name = ${field.name}].`); diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts index a3166873fd091..36d99db9c533e 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/create_scripted_field/errors.ts @@ -43,32 +43,6 @@ export default function ({ getService }: FtrProviderContext) { ); }); - it('returns an error field object is not provided', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - }, - }); - const id = response1.body.index_pattern.id; - const response2 = await supertest - .post(`/api/index_patterns/index_pattern/${id}/scripted_field`) - .send({ - refresh_fields: 123, - field: { - name: 'bar', - type: 'number', - scripted: false, - }, - }); - - expect(response2.status).to.be(400); - expect(response2.body.statusCode).to.be(400); - expect(response2.body.message).to.be( - '[request body.refresh_fields]: expected value of type [boolean] but got [number]' - ); - }); - it('returns an error when creating a non-scripted field', async () => { const title = `foo-${Date.now()}-${Math.random()}*`; const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ From 9a94fc46f7317336802db19a1bbd586afda953a9 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 14:28:09 +0100 Subject: [PATCH 88/93] =?UTF-8?q?style:=20=F0=9F=92=84=20change=20template?= =?UTF-8?q?=20param=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/server/index_patterns/routes/util/handle_errors.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts index 82e2a256bef73..01b8fefb5fab7 100644 --- a/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts +++ b/src/plugins/data/server/index_patterns/routes/util/handle_errors.ts @@ -40,9 +40,9 @@ interface ErrorWithData { * } * ``` */ -export const handleErrors = ( - handler: RequestHandler -): RequestHandler => async (context, request, response) => { +export const handleErrors = ( + handler: RequestHandler +): RequestHandler => async (context, request, response) => { try { return await handler(context, request, response); } catch (error) { From 37a654aa415a0ce05004e9a2405c71dc8f3291ab Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 14:43:07 +0100 Subject: [PATCH 89/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20make=20field.c?= =?UTF-8?q?ount=20always=20be=20an=20integer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/index_patterns/fields/index_pattern_field.ts | 6 +++++- .../common/index_patterns/index_patterns/index_pattern.ts | 3 ++- .../discover/public/application/helpers/popularize_field.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts index e8a9d21ae1cc3..a7160f2e27f90 100644 --- a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts +++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts @@ -42,7 +42,7 @@ export class IndexPatternField implements IFieldType { return this.spec.count || 0; } - public set count(count: number | undefined) { + public set count(count: number) { this.spec.count = count; } @@ -149,6 +149,10 @@ export class IndexPatternField implements IFieldType { return this.aggregatable && !notVisualizableFieldTypes.includes(this.spec.type); } + public deleteCount() { + delete this.spec.count; + } + public toJSON() { return { count: this.count, diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 6aeb4d601c6e0..4c89cbeb446a0 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -369,7 +369,8 @@ export class IndexPattern implements IIndexPattern { const newCount: number | undefined = count === null ? undefined : count; if (fieldObject) { - fieldObject.count = newCount; + if (!newCount) fieldObject.deleteCount(); + else fieldObject.count = newCount; return; } diff --git a/src/plugins/discover/public/application/helpers/popularize_field.ts b/src/plugins/discover/public/application/helpers/popularize_field.ts index 4a23844830a39..0623ac84c55e1 100644 --- a/src/plugins/discover/public/application/helpers/popularize_field.ts +++ b/src/plugins/discover/public/application/helpers/popularize_field.ts @@ -30,7 +30,7 @@ async function popularizeField( return; } - field.count = 1 + (field.count || 0); + field.count++; // Catch 409 errors caused by user adding columns in a higher frequency that the changes can be persisted to Elasticsearch try { From 2bb780fbfe8c2f6bb6d4d5a1130d292e77e4af65 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 14:50:23 +0100 Subject: [PATCH 90/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20aut?= =?UTF-8?q?o-generated=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...plugins-data-public.indexpatternfield.count.md | 4 ++-- ...s-data-public.indexpatternfield.deletecount.md | 15 +++++++++++++++ ...lugin-plugins-data-public.indexpatternfield.md | 3 ++- ...lugins-data-public.indexpatternfield.tojson.md | 4 ++-- ...a-public.indexpatternsservice.createandsave.md | 2 +- ...in-plugins-data-public.indexpatternsservice.md | 2 +- ...kibana-plugin-plugins-data-public.searchbar.md | 4 ++-- ...in-plugins-data-server.indexpatternsservice.md | 2 +- src/plugins/data/public/public.api.md | 12 +++++++----- src/plugins/data/server/server.api.md | 4 ++-- 10 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.deletecount.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md index f01c6c8b4596b..1b8e13a38c6d9 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md @@ -9,7 +9,7 @@ Count is used for field popularity Signature: ```typescript -get count(): number | undefined; +get count(): number; -set count(count: number | undefined); +set count(count: number); ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.deletecount.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.deletecount.md new file mode 100644 index 0000000000000..015894d4cdd25 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.deletecount.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [deleteCount](./kibana-plugin-plugins-data-public.indexpatternfield.deletecount.md) + +## IndexPatternField.deleteCount() method + +Signature: + +```typescript +deleteCount(): void; +``` +Returns: + +`void` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md index a98c7601deb4f..c8118770ed394 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md @@ -22,7 +22,7 @@ export declare class IndexPatternField implements IFieldType | --- | --- | --- | --- | | [aggregatable](./kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md) | | boolean | | | [conflictDescriptions](./kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md) | | Record<string, string[]> | undefined | Description of field type conflicts across different indices in the same index pattern | -| [count](./kibana-plugin-plugins-data-public.indexpatternfield.count.md) | | number | undefined | Count is used for field popularity | +| [count](./kibana-plugin-plugins-data-public.indexpatternfield.count.md) | | number | Count is used for field popularity | | [customLabel](./kibana-plugin-plugins-data-public.indexpatternfield.customlabel.md) | | string | undefined | | | [displayName](./kibana-plugin-plugins-data-public.indexpatternfield.displayname.md) | | string | | | [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | undefined | | @@ -43,6 +43,7 @@ export declare class IndexPatternField implements IFieldType | Method | Modifiers | Description | | --- | --- | --- | +| [deleteCount()](./kibana-plugin-plugins-data-public.indexpatternfield.deletecount.md) | | | | [toJSON()](./kibana-plugin-plugins-data-public.indexpatternfield.tojson.md) | | | | [toSpec({ getFormatterForField, })](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) | | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md index 4960481af3969..f0600dd20658a 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md @@ -8,7 +8,7 @@ ```typescript toJSON(): { - count: number | undefined; + count: number; script: string | undefined; lang: string | undefined; conflictDescriptions: Record | undefined; @@ -26,7 +26,7 @@ toJSON(): { Returns: `{ - count: number | undefined; + count: number; script: string | undefined; lang: string | undefined; conflictDescriptions: Record | undefined; diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md index a4036b2863f02..eebfbb506fb77 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md @@ -4,7 +4,7 @@ ## IndexPatternsService.createAndSave() method -Create a new index pattern and save it right away and make the default index pattern. +Create a new index pattern and save it right away Signature: diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md index 0526455c58253..30ce1fa1de386 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md @@ -41,7 +41,7 @@ export declare class IndexPatternsService | Method | Modifiers | Description | | --- | --- | --- | | [create(spec, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.create.md) | | Create a new index pattern instance | -| [createAndSave(spec, override, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md) | | Create a new index pattern and save it right away and make the default index pattern. | +| [createAndSave(spec, override, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md) | | Create a new index pattern and save it right away | | [createSavedObject(indexPattern, override)](./kibana-plugin-plugins-data-public.indexpatternsservice.createsavedobject.md) | | Save a new index pattern | | [delete(indexPatternId)](./kibana-plugin-plugins-data-public.indexpatternsservice.delete.md) | | Deletes an index pattern from .kibana index | | [updateSavedObject(indexPattern, saveAttempts, ignoreErrors)](./kibana-plugin-plugins-data-public.indexpatternsservice.updatesavedobject.md) | | Save existing index pattern. Will attempt to merge differences if there are conflicts | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md index 0718ca38febbd..2fd84730957b6 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md @@ -7,7 +7,7 @@ Signature: ```typescript -SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "dataTestSubj" | "refreshInterval" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { - WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; +SearchBar: React.ComponentClass, "query" | "isLoading" | "filters" | "indexPatterns" | "dataTestSubj" | "refreshInterval" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { + WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; } ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md index f9df7c3a95c27..c1810a609daf8 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md @@ -7,7 +7,7 @@ Signature: ```typescript -export declare class IndexPatternsService implements Plugin +export declare class IndexPatternsServiceProvider implements Plugin ``` ## Methods diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 888453a9eb6a1..92f49d074fb7c 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1275,12 +1275,14 @@ export class IndexPatternField implements IFieldType { get aggregatable(): boolean; get conflictDescriptions(): Record | undefined; set conflictDescriptions(conflictDescriptions: Record | undefined); - get count(): number | undefined; - set count(count: number | undefined); + get count(): number; + set count(count: number); // (undocumented) get customLabel(): string | undefined; set customLabel(customLabel: string | undefined); // (undocumented) + deleteCount(): void; + // (undocumented) get displayName(): string; // (undocumented) get esTypes(): string[] | undefined; @@ -1306,7 +1308,7 @@ export class IndexPatternField implements IFieldType { get subType(): import("../types").IFieldSubType | undefined; // (undocumented) toJSON(): { - count: number | undefined; + count: number; script: string | undefined; lang: string | undefined; conflictDescriptions: Record | undefined; @@ -2053,8 +2055,8 @@ export const search: { // Warning: (ae-missing-release-tag) "SearchBar" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const SearchBar: React.ComponentClass, "indexPatterns" | "query" | "isLoading" | "filters" | "dataTestSubj" | "refreshInterval" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { - WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; +export const SearchBar: React.ComponentClass, "query" | "isLoading" | "filters" | "indexPatterns" | "dataTestSubj" | "refreshInterval" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "trackUiMetric" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & { + WrappedComponent: React.ComponentType & ReactIntl.InjectedIntlProps>; }; // Warning: (ae-forgotten-export) The symbol "SearchBarOwnProps" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index bcb98e669ff52..97b7930f81213 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -735,7 +735,7 @@ export class IndexPatternsFetcher { } // Warning: (ae-forgotten-export) The symbol "IndexPatternsServiceStart" needs to be exported by the entry point index.d.ts -// Warning: (ae-missing-release-tag) "IndexPatternsService" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "IndexPatternsServiceProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export class IndexPatternsService implements Plugin_3 { @@ -1261,7 +1261,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index_patterns/index_patterns_service.ts:74:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/plugin.ts:91:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/plugin.ts:90:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From 87732fb635d1a7f08b542422ee4bdfa0553da406 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 16:55:31 +0100 Subject: [PATCH 91/93] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20inject=20index?= =?UTF-8?q?=20patterns=20using=20getStartServices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index_patterns/index_patterns_service.ts | 54 ++++++++----------- .../data/server/index_patterns/routes.ts | 26 ++++----- .../routes/create_index_pattern.ts | 9 ++-- .../routes/delete_index_pattern.ts | 9 ++-- .../routes/fields/update_fields.ts | 9 ++-- .../routes/get_index_pattern.ts | 9 ++-- .../scripted_fields/create_scripted_field.ts | 9 ++-- .../scripted_fields/delete_scripted_field.ts | 9 ++-- .../scripted_fields/get_scripted_field.ts | 9 ++-- .../scripted_fields/put_scripted_field.ts | 9 ++-- .../scripted_fields/update_scripted_field.ts | 9 ++-- .../routes/update_index_pattern.ts | 9 ++-- 12 files changed, 84 insertions(+), 86 deletions(-) diff --git a/src/plugins/data/server/index_patterns/index_patterns_service.ts b/src/plugins/data/server/index_patterns/index_patterns_service.ts index 0345e85761efc..0893fc787e526 100644 --- a/src/plugins/data/server/index_patterns/index_patterns_service.ts +++ b/src/plugins/data/server/index_patterns/index_patterns_service.ts @@ -54,10 +54,6 @@ export interface IndexPatternsServiceStartDeps { } export class IndexPatternsServiceProvider implements Plugin { - private uiSettings?: CoreStart['uiSettings']; - private fieldFormats?: FieldFormatsStart; - private logger?: Logger; - public setup( core: CoreSetup, { expressions }: IndexPatternsServiceSetupDeps @@ -65,43 +61,35 @@ export class IndexPatternsServiceProvider implements Plugin { + const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); + const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient); - return new IndexPatternsCommonService({ - uiSettings: new UiSettingsServerToCommon(uiSettingsClient), - savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient), - apiClient: new IndexPatternsApiServer(elasticsearchClient), - fieldFormats: formats, - onError: (error) => { - this.logger!.error(error); + return new IndexPatternsCommonService({ + uiSettings: new UiSettingsServerToCommon(uiSettingsClient), + savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient), + apiClient: new IndexPatternsApiServer(elasticsearchClient), + fieldFormats: formats, + onError: (error) => { + logger.error(error); + }, + onNotification: ({ title, text }) => { + logger.warn(`${title} : ${text}`); + }, + }); }, - onNotification: ({ title, text }) => { - this.logger!.warn(`${title} : ${text}`); - }, - }); + }; } } diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index d0e6789d96ccf..e9dbc2e972c68 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -18,7 +18,7 @@ */ import { schema } from '@kbn/config-schema'; -import { HttpServiceSetup, RequestHandlerContext } from 'kibana/server'; +import { HttpServiceSetup, RequestHandlerContext, StartServicesAccessor } from 'kibana/server'; import { IndexPatternsFetcher } from './fetcher'; import { registerCreateIndexPatternRoute } from './routes/create_index_pattern'; import { registerGetIndexPatternRoute } from './routes/get_index_pattern'; @@ -30,11 +30,11 @@ import { registerPutScriptedFieldRoute } from './routes/scripted_fields/put_scri import { registerGetScriptedFieldRoute } from './routes/scripted_fields/get_scripted_field'; import { registerDeleteScriptedFieldRoute } from './routes/scripted_fields/delete_scripted_field'; import { registerUpdateScriptedFieldRoute } from './routes/scripted_fields/update_scripted_field'; -import type { IndexPatternsServiceProvider } from './index_patterns_service'; +import type { DataPluginStart, DataPluginStartDependencies } from '../plugin'; export function registerRoutes( http: HttpServiceSetup, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) { const parseMetaFields = (metaFields: string | string[]) => { let parsedFields: string[] = []; @@ -49,20 +49,20 @@ export function registerRoutes( const router = http.createRouter(); // Index Patterns API - registerCreateIndexPatternRoute(router, indexPatternsProvider); - registerGetIndexPatternRoute(router, indexPatternsProvider); - registerDeleteIndexPatternRoute(router, indexPatternsProvider); - registerUpdateIndexPatternRoute(router, indexPatternsProvider); + registerCreateIndexPatternRoute(router, getStartServices); + registerGetIndexPatternRoute(router, getStartServices); + registerDeleteIndexPatternRoute(router, getStartServices); + registerUpdateIndexPatternRoute(router, getStartServices); // Fields API - registerUpdateFieldsRoute(router, indexPatternsProvider); + registerUpdateFieldsRoute(router, getStartServices); // Scripted Field API - registerCreateScriptedFieldRoute(router, indexPatternsProvider); - registerPutScriptedFieldRoute(router, indexPatternsProvider); - registerGetScriptedFieldRoute(router, indexPatternsProvider); - registerDeleteScriptedFieldRoute(router, indexPatternsProvider); - registerUpdateScriptedFieldRoute(router, indexPatternsProvider); + registerCreateScriptedFieldRoute(router, getStartServices); + registerPutScriptedFieldRoute(router, getStartServices); + registerGetScriptedFieldRoute(router, getStartServices); + registerDeleteScriptedFieldRoute(router, getStartServices); + registerUpdateScriptedFieldRoute(router, getStartServices); router.get( { diff --git a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts index 147fcd14f1472..57a745b19748d 100644 --- a/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/create_index_pattern.ts @@ -19,10 +19,10 @@ import { schema } from '@kbn/config-schema'; import { IndexPatternSpec } from 'src/plugins/data/common'; -import { IRouter } from '../../../../../core/server'; import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; -import type { IndexPatternsServiceProvider } from '../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; const indexPatternSpecSchema = schema.object({ title: schema.string(), @@ -54,7 +54,7 @@ const indexPatternSpecSchema = schema.object({ export const registerCreateIndexPatternRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.post( { @@ -71,7 +71,8 @@ export const registerCreateIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts index a9a3d10919d2d..c73718342355f 100644 --- a/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/delete_index_pattern.ts @@ -18,13 +18,13 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../core/server'; import { handleErrors } from './util/handle_errors'; -import type { IndexPatternsServiceProvider } from '../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; export const registerDeleteIndexPatternRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.delete( { @@ -45,7 +45,8 @@ export const registerDeleteIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts index 5fc2f742a6170..4dd9046e70ad1 100644 --- a/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts +++ b/src/plugins/data/server/index_patterns/routes/fields/update_fields.ts @@ -18,14 +18,14 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../../core/server'; import { handleErrors } from '../util/handle_errors'; import { serializedFieldFormatSchema } from '../util/schemas'; -import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; export const registerUpdateFieldsRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.post( { @@ -66,7 +66,8 @@ export const registerUpdateFieldsRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts index 19c95b378257a..5f7825e9cff90 100644 --- a/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/get_index_pattern.ts @@ -18,13 +18,13 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../core/server'; import { handleErrors } from './util/handle_errors'; -import type { IndexPatternsServiceProvider } from '../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; export const registerGetIndexPatternRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.get( { @@ -45,7 +45,8 @@ export const registerGetIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts index 7c4a82fe87dcf..23a293d5d9141 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/create_scripted_field.ts @@ -18,14 +18,14 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../../core/server'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; -import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; export const registerCreateScriptedFieldRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.post( { @@ -49,7 +49,8 @@ export const registerCreateScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts index 92ddddb4ae93d..453ad1fdc16ed 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/delete_scripted_field.ts @@ -18,14 +18,14 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; -import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; export const registerDeleteScriptedFieldRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.delete( { @@ -50,7 +50,8 @@ export const registerDeleteScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts index 551f244a6d1a4..35b0e673a7e56 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/get_scripted_field.ts @@ -18,14 +18,14 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; -import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; export const registerGetScriptedFieldRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.get( { @@ -50,7 +50,8 @@ export const registerGetScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts index 6eb311dd4d1ce..a789affab3579 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/put_scripted_field.ts @@ -18,14 +18,14 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../../core/server'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; -import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; export const registerPutScriptedFieldRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.put( { @@ -49,7 +49,8 @@ export const registerPutScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts index 490dc7a060491..9b937aafd6aa7 100644 --- a/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data/server/index_patterns/routes/scripted_fields/update_scripted_field.ts @@ -19,15 +19,15 @@ import { schema } from '@kbn/config-schema'; import { FieldSpec } from 'src/plugins/data/common'; -import { IRouter } from '../../../../../../core/server'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchemaFields } from '../util/schemas'; -import type { IndexPatternsServiceProvider } from '../../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; export const registerUpdateScriptedFieldRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.post( { @@ -70,7 +70,8 @@ export const registerUpdateScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts index 6d6486ec90314..10567544af6ea 100644 --- a/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts +++ b/src/plugins/data/server/index_patterns/routes/update_index_pattern.ts @@ -18,10 +18,10 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter } from '../../../../../core/server'; import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, serializedFieldFormatSchema } from './util/schemas'; -import type { IndexPatternsServiceProvider } from '../index_patterns_service'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; const indexPatternUpdateSchema = schema.object({ title: schema.maybe(schema.string()), @@ -42,7 +42,7 @@ const indexPatternUpdateSchema = schema.object({ export const registerUpdateIndexPatternRoute = ( router: IRouter, - indexPatternsProvider: IndexPatternsServiceProvider + getStartServices: StartServicesAccessor ) => { router.post( { @@ -67,7 +67,8 @@ export const registerUpdateIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const indexPatternsService = await indexPatternsProvider.createIndexPatternsService( + const [, , { indexPatterns }] = await getStartServices(); + const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); From 0a3bb86b25e55cc0973b08fff6a3766406c98e59 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 17:02:40 +0100 Subject: [PATCH 92/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20aut?= =?UTF-8?q?ogenerated=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ternsservice.createindexpatternsservice.md | 23 ------------------- ...lugins-data-server.indexpatternsservice.md | 1 - ...-data-server.indexpatternsservice.start.md | 4 ++-- src/plugins/data/server/server.api.md | 8 +++---- 4 files changed, 5 insertions(+), 31 deletions(-) delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md deleted file mode 100644 index a1848adb75913..0000000000000 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md +++ /dev/null @@ -1,23 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) > [createIndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.createindexpatternsservice.md) - -## IndexPatternsService.createIndexPatternsService() method - -Signature: - -```typescript -createIndexPatternsService(savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient): Promise; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| savedObjectsClient | SavedObjectsClientContract | | -| elasticsearchClient | ElasticsearchClient | | - -Returns: - -`Promise` - diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md index c1810a609daf8..83e912d80dbd1 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.md @@ -14,7 +14,6 @@ export declare class IndexPatternsServiceProvider implements Plugin, elasticsearchClient: ElasticsearchClient) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise; }; ``` @@ -22,6 +22,6 @@ start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): Returns: `{ - indexPatternsServiceFactory: (savedObjectsClient: Pick, elasticsearchClient: ElasticsearchClient) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise; }` diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 97b7930f81213..31fb1a48e9585 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -739,8 +739,6 @@ export class IndexPatternsFetcher { // // @public (undocumented) export class IndexPatternsService implements Plugin_3 { - // (undocumented) - createIndexPatternsService(savedObjectsClient: SavedObjectsClientContract_2, elasticsearchClient: ElasticsearchClient_2): Promise; // Warning: (ae-forgotten-export) The symbol "DataPluginStartDependencies" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "IndexPatternsServiceSetupDeps" needs to be exported by the entry point index.d.ts // @@ -750,9 +748,9 @@ export class IndexPatternsService implements Plugin_3, elasticsearchClient: ElasticsearchClient_2) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract_2, elasticsearchClient: ElasticsearchClient_2) => Promise; }; - } +} // Warning: (ae-missing-release-tag) "ISearchOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -1260,7 +1258,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:271:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index_patterns/index_patterns_service.ts:74:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index_patterns/index_patterns_service.ts:70:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts // src/plugins/data/server/plugin.ts:90:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts From 28086cbe87a8e9b79c6e4549ea3cf9e95165ecf6 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 7 Dec 2020 17:13:48 +0100 Subject: [PATCH 93/93] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20doc?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/data/README.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/plugins/data/README.md b/src/plugins/data/README.md index fe2d9a4cfbf90..0c3d8d4072aae 100644 --- a/src/plugins/data/README.md +++ b/src/plugins/data/README.md @@ -296,17 +296,6 @@ POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fiel } ``` -- `refresh_fields` — if set to `true` reloads index pattern fields after - the index pattern is stored. Defaults to `false`. - -``` -POST /api/index_patterns/index_pattern/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/fields -{ - "refresh_fields": true, - "fields": {} -} -``` - This endpoint returns the updated index pattern object. ```json