mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
parent
e69a2e1a36
commit
ccff96340f
1 changed files with 27 additions and 7 deletions
|
@ -30,14 +30,29 @@ async function getSavedObject(doc, services) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addJsonFieldToIndexPattern(target, sourceString, fieldName, indexName) {
|
||||||
|
if (sourceString) {
|
||||||
|
try {
|
||||||
|
target[fieldName] = JSON.parse(sourceString);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`Error encountered parsing ${fieldName} for index pattern ${indexName}: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
async function importIndexPattern(doc, indexPatterns, overwriteAll) {
|
async function importIndexPattern(doc, indexPatterns, overwriteAll) {
|
||||||
// TODO: consolidate this is the code in create_index_pattern_wizard.js
|
// TODO: consolidate this is the code in create_index_pattern_wizard.js
|
||||||
const emptyPattern = await indexPatterns.get();
|
const emptyPattern = await indexPatterns.get();
|
||||||
Object.assign(emptyPattern, {
|
const { title, timeFieldName, fields, fieldFormatMap, sourceFilters } = doc._source;
|
||||||
|
const importedIndexPattern = {
|
||||||
id: doc._id,
|
id: doc._id,
|
||||||
title: doc._source.title,
|
title,
|
||||||
timeFieldName: doc._source.timeFieldName,
|
timeFieldName
|
||||||
});
|
};
|
||||||
|
addJsonFieldToIndexPattern(importedIndexPattern, fields, 'fields', title);
|
||||||
|
addJsonFieldToIndexPattern(importedIndexPattern, fieldFormatMap, 'fieldFormatMap', title);
|
||||||
|
addJsonFieldToIndexPattern(importedIndexPattern, sourceFilters, 'sourceFilters', title);
|
||||||
|
Object.assign(emptyPattern, importedIndexPattern);
|
||||||
|
|
||||||
const newId = await emptyPattern.create(true, !overwriteAll);
|
const newId = await emptyPattern.create(true, !overwriteAll);
|
||||||
indexPatterns.cache.clear(newId);
|
indexPatterns.cache.clear(newId);
|
||||||
return newId;
|
return newId;
|
||||||
|
@ -148,14 +163,19 @@ export async function resolveSavedObjects(
|
||||||
// Keep track of how many we actually import because the user
|
// Keep track of how many we actually import because the user
|
||||||
// can cancel an override
|
// can cancel an override
|
||||||
let importedObjectCount = 0;
|
let importedObjectCount = 0;
|
||||||
|
const failedImports = [];
|
||||||
// Start with the index patterns since everything is dependent on them
|
// Start with the index patterns since everything is dependent on them
|
||||||
await awaitEachItemInParallel(
|
await awaitEachItemInParallel(
|
||||||
docTypes.indexPatterns,
|
docTypes.indexPatterns,
|
||||||
async indexPatternDoc => {
|
async indexPatternDoc => {
|
||||||
if (await importIndexPattern(indexPatternDoc, indexPatterns, overwriteAll)) {
|
try {
|
||||||
|
const importedIndexPatternId = await importIndexPattern(indexPatternDoc, indexPatterns, overwriteAll);
|
||||||
|
if (importedIndexPatternId) {
|
||||||
importedObjectCount++;
|
importedObjectCount++;
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
failedImports.push({ indexPatternDoc, error });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue