[ML] Fix new job wizard with multiple indices (#64567)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
James Gowdy 2020-04-28 20:45:57 +01:00 committed by GitHub
parent dfb4c331a0
commit b5fb78bfce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 6 deletions

View file

@ -52,3 +52,5 @@ export function getLatestDataOrBucketTimestamp(
): number;
export function prefixDatafeedId(datafeedId: string, prefix: string): string;
export function splitIndexPatternNames(indexPatternName: string): string[];

View file

@ -588,3 +588,9 @@ export function processCreatedBy(customSettings) {
delete customSettings.created_by;
}
}
export function splitIndexPatternNames(indexPatternName) {
return indexPatternName.includes(',')
? indexPatternName.split(',').map(i => i.trim())
: [indexPatternName];
}

View file

@ -7,6 +7,7 @@
import { IndexPatternTitle } from '../../../../../../../common/types/kibana';
import { Field, Aggregation, EVENT_RATE_FIELD_ID } from '../../../../../../../common/types/fields';
import { Job, Datafeed, Detector } from '../../../../../../../common/types/anomaly_detection_jobs';
import { splitIndexPatternNames } from '../../../../../../../common/util/job_utils';
export function createEmptyJob(): Job {
return {
@ -28,7 +29,7 @@ export function createEmptyDatafeed(indexPatternTitle: IndexPatternTitle): Dataf
return {
datafeed_id: '',
job_id: '',
indices: [indexPatternTitle],
indices: splitIndexPatternNames(indexPatternTitle),
query: {},
};
}

View file

@ -50,7 +50,7 @@ function getWizardUrlFromCloningJob(job: CombinedJob) {
break;
}
const indexPatternId = getIndexPatternIdFromName(job.datafeed_config.indices[0]);
const indexPatternId = getIndexPatternIdFromName(job.datafeed_config.indices.join());
return `jobs/new_job/${page}?index=${indexPatternId}&_g=()`;
}

View file

@ -29,7 +29,11 @@ import {
JobSpecificOverride,
isGeneralJobOverride,
} from '../../../common/types/modules';
import { getLatestDataOrBucketTimestamp, prefixDatafeedId } from '../../../common/util/job_utils';
import {
getLatestDataOrBucketTimestamp,
prefixDatafeedId,
splitIndexPatternNames,
} from '../../../common/util/job_utils';
import { mlLog } from '../../client/log';
import { calculateModelMemoryLimitProvider } from '../calculate_model_memory_limit';
import { fieldsServiceProvider } from '../fields_service';
@ -828,9 +832,7 @@ export class DataRecognizer {
updateDatafeedIndices(moduleConfig: Module) {
// if the supplied index pattern contains a comma, split into multiple indices and
// add each one to the datafeed
const indexPatternNames = this.indexPatternName.includes(',')
? this.indexPatternName.split(',').map(i => i.trim())
: [this.indexPatternName];
const indexPatternNames = splitIndexPatternNames(this.indexPatternName);
moduleConfig.datafeeds.forEach(df => {
const newIndices: string[] = [];