Skip to content

Commit

Permalink
Adapt struct for convention, determine which fields not to index
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jul 1, 2020
1 parent dbd8cc5 commit 44cd5a2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/plugins/discover/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<object, object> {
public setup(core: CoreSetup) {
core.capabilities.registerProvider(capabilitiesProvider);
core.uiSettings.register(uiSettings);
core.savedObjects.registerType(searchSavedObjectType);
core.savedObjects.registerType(search);

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 { search } from './search';
Original file line number Diff line number Diff line change
Expand Up @@ -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',
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' },
},
},
migrations: searchSavedObjectTypeMigrations,
migrations: searchMigrations,
};
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 '../../data/common';
import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';

const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = (doc) => {
const searchSourceJSON = get<string>(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<SavedObjectMigrationFn<any, any>>(migrateMatchAllQuery),
'7.0.0': flow<SavedObjectMigrationFn<any, any>>(setNewReferences),
'7.4.0': flow<SavedObjectMigrationFn<any, any>>(migrateSearchSortToNestedArray),
Expand Down

0 comments on commit 44cd5a2

Please sign in to comment.