Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Migrate server side saved object from data to discover plugin #70342

2 changes: 0 additions & 2 deletions src/plugins/data/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

export { searchSavedObjectType } from './search';
export { querySavedObjectType } from './query';
export { indexPatternSavedObjectType } from './index_patterns';
export { kqlTelemetry } from './kql_telementry';
3 changes: 0 additions & 3 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from './types';
import { registerSearchRoute } from './routes';
import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search';
import { searchSavedObjectType } from '../saved_objects';
import { DataPluginStart } from '../plugin';

export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
Expand All @@ -36,8 +35,6 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
constructor(private initializerContext: PluginInitializerContext) {}

public setup(core: CoreSetup<object, DataPluginStart>): ISearchSetup {
core.savedObjects.registerType(searchSavedObjectType);

this.registerSearchStrategy(
ES_SEARCH_STRATEGY,
esSearchStrategyProvider(this.initializerContext.config.legacy.globalConfig$)
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/discover/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import { CoreSetup, CoreStart, Plugin } from 'kibana/server';
import { uiSettings } from './ui_settings';
import { capabilitiesProvider } from './capabilities_provider';
import { searchSavedObjectType } from './saved_objects';

export class DiscoverServerPlugin implements Plugin<object, object> {
public setup(core: CoreSetup) {
core.capabilities.registerProvider(capabilitiesProvider);
core.uiSettings.register(uiSettings);
core.savedObjects.registerType(searchSavedObjectType);

return {};
}
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/discover/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
@@ -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 { searchSavedObjectType } from './search';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { SavedObjectsType } from 'kibana/server';
import { searchSavedObjectTypeMigrations } from './search_migrations';
import { searchMigrations } from './search_migrations';

export const searchSavedObjectType: SavedObjectsType = {
name: 'search',
Expand All @@ -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' },
kertal marked this conversation as resolved.
Show resolved Hide resolved
},
},
migrations: searchSavedObjectTypeMigrations as any,
migrations: searchMigrations as any,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { flow, get } from 'lodash';
import { SavedObjectMigrationFn } from 'kibana/server';
import { DEFAULT_QUERY_LANGUAGE } from '../../common';
import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';

const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = (doc) => {
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
Expand Down Expand Up @@ -121,7 +121,7 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn<any, any> = (doc) =
};
};

export const searchSavedObjectTypeMigrations = {
export const searchMigrations = {
'6.7.2': flow(migrateMatchAllQuery),
'7.0.0': flow(setNewReferences),
'7.4.0': flow(migrateSearchSortToNestedArray),
Expand Down