diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/app_state_settings.js b/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/app_state_settings.js index aab94fb788411..2bce3b72762ae 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/app_state_settings.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/app_state_settings.js @@ -43,7 +43,7 @@ function populateSingleMetricSettings(jobSettings, scope) { if (f.agg !== undefined) { // find the aggregation object in the aggTypeOptions list which has the same name // as the agg setting in the url - const agg = scope.ui.aggTypeOptions.find(o => (o.name === f.agg)); + const agg = scope.ui.aggTypeOptions.find(o => (o.mlName === f.agg)); if (agg !== undefined) { scope.formConfig.agg.type = agg; scope.aggChange(); @@ -83,7 +83,7 @@ function populateMultiMetricSettings(jobSettings, scope) { } if (f.agg !== undefined) { - const agg = scope.ui.aggTypeOptions.find(o => (o.name === f.agg)); + const agg = scope.ui.aggTypeOptions.find(o => (o.mlName === f.agg)); if (agg !== undefined) { scope.formConfig.fields[field.id].agg.type = agg; } @@ -124,7 +124,7 @@ function populatePopulationSettings(jobSettings, scope) { if (field !== undefined) { if (f.agg !== undefined) { - const agg = scope.ui.aggTypeOptions.find(o => (o.name === f.agg)); + const agg = scope.ui.aggTypeOptions.find(o => (o.mlName === f.agg)); if (agg !== undefined) { field.agg = { type: agg }; } diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/prepopulate_job_settings.js b/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/prepopulate_job_settings.js index 047f056e542f3..482b6195cd485 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/prepopulate_job_settings.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/components/utils/prepopulate_job_settings.js @@ -33,7 +33,7 @@ export function jobSettingsFromJob(job, aggTypeOptions) { function getKibanaAggName(mlAggName) { const agg = aggTypeOptions.find(a => a.mlName === mlAggName); - return (agg) ? agg.name : undefined; + return (agg) ? agg.mlName : undefined; } const jobSettings = {}; @@ -43,7 +43,19 @@ export function jobSettingsFromJob(job, aggTypeOptions) { if (job.custom_settings.created_by === WIZARD_TYPE.SINGLE_METRIC) { // single metric const d = dtrs[0]; - const field = { agg: getKibanaAggName(d.function, aggTypeOptions) }; + let func = d.function; + + // distinct_count jobs in single metric wizard use a particular aggregation where + // the detector function is replaced as non_zero_count. + // here we look for this exact situation and switch the function back to distinct_count + if ( + func === 'non_zero_count' && + job.analysis_config.summary_count_field_name !== undefined && + job.analysis_config.summary_count_field_name.match(/^dc_.+/)) { + func = 'distinct_count'; + } + + const field = { agg: getKibanaAggName(func) }; if (d.field_name) { field.fieldName = d.field_name; } @@ -58,7 +70,7 @@ export function jobSettingsFromJob(job, aggTypeOptions) { splitField = d.partition_field_name; } - const field = { agg: getKibanaAggName(d.function, aggTypeOptions) }; + const field = { agg: getKibanaAggName(d.function) }; if (d.field_name) { field.fieldName = d.field_name; } @@ -79,7 +91,7 @@ export function jobSettingsFromJob(job, aggTypeOptions) { overField = d.over_field_name; } - const field = { agg: getKibanaAggName(d.function, aggTypeOptions) }; + const field = { agg: getKibanaAggName(d.function) }; if (d.field_name) { field.fieldName = d.field_name; } diff --git a/x-pack/plugins/ml/public/services/job_service.js b/x-pack/plugins/ml/public/services/job_service.js index 3abb739de0894..416f665b1d1fb 100644 --- a/x-pack/plugins/ml/public/services/job_service.js +++ b/x-pack/plugins/ml/public/services/job_service.js @@ -548,6 +548,12 @@ class JobService { } } + // when jumping from a wizard to the advanced job creation, + // the wizard's created_by information should be stripped. + if (tempJob.custom_settings && tempJob.custom_settings.created_by) { + delete tempJob.custom_settings.created_by; + } + return tempJob; }