Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ElasticIndex fetchInfo handles v7 indices 1`] = `
Object {
"aliases": Object {
"foo": ".baz",
},
"exists": true,
"indexName": ".baz",
"mappings": Object {
"doc": Object {
"dynamic": "strict",
"properties": Object {
"a": "b",
},
},
},
}
`;

exports[`ElasticIndex write writes documents in bulk to the index 1`] = `
Array [
"bulk",
Expand Down
6 changes: 5 additions & 1 deletion src/server/saved_objects/migrations/core/call_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface CallCluster {
(path: 'indices.create' | 'indices.delete', opts: IndexCreationOpts): Promise<any>;
(path: 'indices.exists', opts: IndexOpts): Promise<boolean>;
(path: 'indices.existsAlias', opts: { name: string }): Promise<boolean>;
(path: 'indices.get', opts: IndexOpts & Ignorable): Promise<IndicesInfo | NotFound>;
(path: 'indices.get', opts: IndicesGetOptions): Promise<IndicesInfo | NotFound>;
(path: 'indices.getAlias', opts: { name: string } & Ignorable): Promise<AliasResult | NotFound>;
(path: 'indices.getMapping', opts: IndexOpts): Promise<MappingResult>;
(path: 'indices.getSettings', opts: IndexOpts): Promise<IndexSettingsResult>;
Expand Down Expand Up @@ -127,6 +127,10 @@ export interface ScrollOpts {
scrollId: string;
}

export interface IndicesGetOptions extends IndexOpts, Ignorable {
include_type_name?: boolean;
}

///////////////////////////////////////////////////////////////////
// callCluster result type definitions
///////////////////////////////////////////////////////////////////
Expand Down
28 changes: 10 additions & 18 deletions src/server/saved_objects/migrations/core/elastic_index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,6 @@ describe('ElasticIndex', () => {
);
});

test('handles v7 indices', async () => {
const callCluster = sinon.spy(async (path: string, { index }: any) => {
return {
[index]: {
aliases: { foo: index },
mappings: {
dynamic: 'strict',
properties: { a: 'b' },
},
},
};
});

const result = await Index.fetchInfo(callCluster, '.baz');
expect(result).toMatchSnapshot();
});

test('fails if there are multiple root types', async () => {
const callCluster = sinon.spy(async (path: string, { index }: any) => {
return {
Expand Down Expand Up @@ -658,7 +641,16 @@ describe('ElasticIndex', () => {
});

expect(hasMigrations).toBeFalsy();
expect(callCluster.args).toEqual([['indices.get', { ignore: [404], index: '.myalias' }]]);
expect(callCluster.args).toEqual([
[
'indices.get',
{
ignore: [404],
index: '.myalias',
include_type_name: true,
},
],
]);
});

test('is true if there are no migrations defined', async () => {
Expand Down
28 changes: 6 additions & 22 deletions src/server/saved_objects/migrations/core/elastic_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export interface FullIndexInfo {
* index mappings are somewhat what we expect.
*/
export async function fetchInfo(callCluster: CallCluster, index: string): Promise<FullIndexInfo> {
const result = await callCluster('indices.get', { ignore: [404], index });
const result = await callCluster('indices.get', {
ignore: [404],
index,
include_type_name: true,
});

if ((result as NotFound).status === 404) {
return {
Expand All @@ -65,7 +69,7 @@ export async function fetchInfo(callCluster: CallCluster, index: string): Promis

const [indexName, indexInfo] = Object.entries(result)[0];

return assertIsSupportedIndex({ ...normalizeV6AndV7(indexInfo), exists: true, indexName });
return assertIsSupportedIndex({ ...indexInfo, exists: true, indexName });
}

/**
Expand Down Expand Up @@ -287,26 +291,6 @@ export async function claimAlias(
await callCluster('indices.refresh', { index });
}

/**
* ES7 removed the "doc" property from mappings. This function takes a v6 or v7
* index info object and returns an object in v6 form.
*/
function normalizeV6AndV7(indexInfo: FullIndexInfo) {
const mappings = indexInfo.mappings as any;
const isV7Index = !mappings.doc && mappings.dynamic && mappings.properties;

if (!isV7Index) {
return indexInfo;
}

return {
...indexInfo,
mappings: {
doc: mappings,
},
};
}

/**
* This is a rough check to ensure that the index being migrated satisfies at least
* some rudimentary expectations. Past Kibana indices had multiple root documents, etc
Expand Down
3 changes: 2 additions & 1 deletion src/ui/ui_settings/routes/__tests__/index_missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export function indexMissingSuite() {
// but automatically by writing to es when index didn't exist
async assertValidKibanaIndex() {
const resp = await callCluster('indices.get', {
index: indexName
index: indexName,
include_type_name: true,
});

expect(resp[indexName].mappings).to.have.property('doc');
Expand Down