mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -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;
|
||||
}
|
||||
|
||||
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) {
|
||||
// TODO: consolidate this is the code in create_index_pattern_wizard.js
|
||||
const emptyPattern = await indexPatterns.get();
|
||||
Object.assign(emptyPattern, {
|
||||
const { title, timeFieldName, fields, fieldFormatMap, sourceFilters } = doc._source;
|
||||
const importedIndexPattern = {
|
||||
id: doc._id,
|
||||
title: doc._source.title,
|
||||
timeFieldName: doc._source.timeFieldName,
|
||||
});
|
||||
title,
|
||||
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);
|
||||
indexPatterns.cache.clear(newId);
|
||||
return newId;
|
||||
|
@ -148,13 +163,18 @@ export async function resolveSavedObjects(
|
|||
// Keep track of how many we actually import because the user
|
||||
// can cancel an override
|
||||
let importedObjectCount = 0;
|
||||
|
||||
const failedImports = [];
|
||||
// Start with the index patterns since everything is dependent on them
|
||||
await awaitEachItemInParallel(
|
||||
docTypes.indexPatterns,
|
||||
async indexPatternDoc => {
|
||||
if (await importIndexPattern(indexPatternDoc, indexPatterns, overwriteAll)) {
|
||||
importedObjectCount++;
|
||||
try {
|
||||
const importedIndexPatternId = await importIndexPattern(indexPatternDoc, indexPatterns, overwriteAll);
|
||||
if (importedIndexPatternId) {
|
||||
importedObjectCount++;
|
||||
}
|
||||
} catch (error) {
|
||||
failedImports.push({ indexPatternDoc, error });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue