Skip to content

Commit

Permalink
Clean up ML saved object bulkCreate usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jportner committed Aug 26, 2020
1 parent 0787f26 commit e139252
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getAuthorizationHeader } from '../../lib/request_authorization';
import { MlInfoResponse } from '../../../common/types/ml_server_info';
import {
KibanaObjects,
KibanaObjectConfig,
ModuleDataFeed,
ModuleJob,
Module,
Expand Down Expand Up @@ -100,7 +101,7 @@ interface ObjectExistResponse {
id: string;
type: string;
exists: boolean;
savedObject?: any;
savedObject?: { id: string; type: string; attributes: KibanaObjectConfig };
}

interface SaveResults {
Expand Down Expand Up @@ -678,14 +679,14 @@ export class DataRecognizer {
let results = { saved_objects: [] as any[] };
const filteredSavedObjects = objectExistResults
.filter((o) => o.exists === false)
.map((o) => o.savedObject);
.map((o) => o.savedObject!);
if (filteredSavedObjects.length) {
results = await this.savedObjectsClient.bulkCreate(
// Add an empty migrationVersion attribute to each saved object to ensure
// it is automatically migrated to the 7.0+ format with a references attribute.
filteredSavedObjects.map((doc) => ({
...doc,
migrationVersion: doc.migrationVersion || {},
migrationVersion: {},
}))
);
}
Expand Down

0 comments on commit e139252

Please sign in to comment.