From 44cd5a2979cbf0dd8d1ecc0f2e0654cc5cdfc39d Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Wed, 1 Jul 2020 11:07:14 +0200 Subject: [PATCH] Adapt struct for convention, determine which fields not to index --- src/plugins/discover/server/plugin.ts | 4 ++-- .../discover/server/saved_objects/index.ts | 20 +++++++++++++++++++ .../server/{ => saved_objects}/search.ts | 14 ++++++------- .../search_migrations.test.ts | 8 ++++---- .../{ => saved_objects}/search_migrations.ts | 4 ++-- 5 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 src/plugins/discover/server/saved_objects/index.ts rename src/plugins/discover/server/{ => saved_objects}/search.ts (82%) rename src/plugins/discover/server/{ => saved_objects}/search_migrations.test.ts (96%) rename src/plugins/discover/server/{ => saved_objects}/search_migrations.ts (97%) diff --git a/src/plugins/discover/server/plugin.ts b/src/plugins/discover/server/plugin.ts index 4e7764c809f00..e24e4846cc185 100644 --- a/src/plugins/discover/server/plugin.ts +++ b/src/plugins/discover/server/plugin.ts @@ -20,13 +20,13 @@ import { CoreSetup, CoreStart, Plugin } from 'kibana/server'; import { uiSettings } from './ui_settings'; import { capabilitiesProvider } from './capabilities_provider'; -import { searchSavedObjectType } from './search'; +import { search } from './saved_objects'; export class DiscoverServerPlugin implements Plugin { public setup(core: CoreSetup) { core.capabilities.registerProvider(capabilitiesProvider); core.uiSettings.register(uiSettings); - core.savedObjects.registerType(searchSavedObjectType); + core.savedObjects.registerType(search); return {}; } diff --git a/src/plugins/discover/server/saved_objects/index.ts b/src/plugins/discover/server/saved_objects/index.ts new file mode 100644 index 0000000000000..8caf811f381b8 --- /dev/null +++ b/src/plugins/discover/server/saved_objects/index.ts @@ -0,0 +1,20 @@ +/* + * 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 { search } from './search'; diff --git a/src/plugins/discover/server/search.ts b/src/plugins/discover/server/saved_objects/search.ts similarity index 82% rename from src/plugins/discover/server/search.ts rename to src/plugins/discover/server/saved_objects/search.ts index 437c83f67bf5d..fe68db7fa0440 100644 --- a/src/plugins/discover/server/search.ts +++ b/src/plugins/discover/server/saved_objects/search.ts @@ -18,9 +18,9 @@ */ import { SavedObjectsType } from 'kibana/server'; -import { searchSavedObjectTypeMigrations } from './search_migrations'; +import { searchMigrations } from './search_migrations'; -export const searchSavedObjectType: SavedObjectsType = { +export const search: SavedObjectsType = { name: 'search', hidden: false, namespaceType: 'single', @@ -43,18 +43,18 @@ export const searchSavedObjectType: SavedObjectsType = { }, mappings: { properties: { - columns: { type: 'keyword' }, + columns: { type: 'keyword', index: false }, description: { type: 'text' }, - hits: { type: 'integer' }, + hits: { type: 'integer', index: false }, kibanaSavedObjectMeta: { properties: { - searchSourceJSON: { type: 'text' }, + searchSourceJSON: { type: 'text', index: false }, }, }, - sort: { type: 'keyword' }, + sort: { type: 'keyword', index: false }, title: { type: 'text' }, version: { type: 'integer' }, }, }, - migrations: searchSavedObjectTypeMigrations, + migrations: searchMigrations, }; diff --git a/src/plugins/discover/server/search_migrations.test.ts b/src/plugins/discover/server/saved_objects/search_migrations.test.ts similarity index 96% rename from src/plugins/discover/server/search_migrations.test.ts rename to src/plugins/discover/server/saved_objects/search_migrations.test.ts index 69db08a689255..babd25c03dbb2 100644 --- a/src/plugins/discover/server/search_migrations.test.ts +++ b/src/plugins/discover/server/saved_objects/search_migrations.test.ts @@ -18,13 +18,13 @@ */ import { SavedObjectMigrationContext } from 'kibana/server'; -import { searchSavedObjectTypeMigrations } from './search_migrations'; +import { searchMigrations } from './search_migrations'; const savedObjectMigrationContext = (null as unknown) as SavedObjectMigrationContext; describe('migration search', () => { describe('6.7.2', () => { - const migrationFn = searchSavedObjectTypeMigrations['6.7.2']; + const migrationFn = searchMigrations['6.7.2']; it('should migrate obsolete match_all query', () => { const migratedDoc = migrationFn( @@ -56,7 +56,7 @@ describe('migration search', () => { }); describe('7.0.0', () => { - const migrationFn = searchSavedObjectTypeMigrations['7.0.0']; + const migrationFn = searchMigrations['7.0.0']; test('skips errors when searchSourceJSON is null', () => { const doc = { @@ -278,7 +278,7 @@ Object { }); describe('7.4.0', function () { - const migrationFn = searchSavedObjectTypeMigrations['7.4.0']; + const migrationFn = searchMigrations['7.4.0']; test('transforms one dimensional sort arrays into two dimensional arrays', () => { const doc = { diff --git a/src/plugins/discover/server/search_migrations.ts b/src/plugins/discover/server/saved_objects/search_migrations.ts similarity index 97% rename from src/plugins/discover/server/search_migrations.ts rename to src/plugins/discover/server/saved_objects/search_migrations.ts index 3834e5188015b..a99e134e4d9ad 100644 --- a/src/plugins/discover/server/search_migrations.ts +++ b/src/plugins/discover/server/saved_objects/search_migrations.ts @@ -19,7 +19,7 @@ import { flow, get } from 'lodash'; import { SavedObjectMigrationFn } from 'kibana/server'; -import { DEFAULT_QUERY_LANGUAGE } from '../../data/common'; +import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common'; const migrateMatchAllQuery: SavedObjectMigrationFn = (doc) => { const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON'); @@ -121,7 +121,7 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn = (doc) = }; }; -export const searchSavedObjectTypeMigrations = { +export const searchMigrations = { '6.7.2': flow>(migrateMatchAllQuery), '7.0.0': flow>(setNewReferences), '7.4.0': flow>(migrateSearchSortToNestedArray),