From e503b87eb2c5fbcb8a9704ed53004c42f333d59b Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Mon, 23 Jul 2018 14:37:16 +0200 Subject: [PATCH] [ML] Job validation no longer reports an error when categorization job is properly setup. (#21075) For categorization jobs, job validation would report that mlcategory isn't an aggregatable field. This fix checks the job configuration and only reports the error if the job config isn't using categorization_field_name and the detector field isn't set to mlcategory. --- .../__tests__/job_validation.js | 34 +++++++++++++++++++ .../job_validation/validate_cardinality.js | 15 +++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/ml/server/models/job_validation/__tests__/job_validation.js b/x-pack/plugins/ml/server/models/job_validation/__tests__/job_validation.js index 46a47f4de979..d11a07e85541 100644 --- a/x-pack/plugins/ml/server/models/job_validation/__tests__/job_validation.js +++ b/x-pack/plugins/ml/server/models/job_validation/__tests__/job_validation.js @@ -291,6 +291,40 @@ describe('ML - validateJob', () => { ); }); + it('categorization job using mlcategory passes aggregatable field check', () => { + const payload = { + job: { + job_id: 'categorization_test', + analysis_config: { + bucket_span: '15m', + detectors: [{ + function: 'count', + by_field_name: 'mlcategory' + }], + categorization_field_name: 'message_text', + influencers: [] + }, + data_description: { time_field: '@timestamp' }, + datafeed_config: { indices: [] } + }, + fields: { testField: {} } + }; + + return validateJob(callWithRequest, payload).then( + (messages) => { + const ids = messages.map(m => m.id); + expect(ids).to.eql([ + 'job_id_valid', + 'detectors_function_not_empty', + 'index_fields_valid', + 'success_cardinality', + 'time_field_invalid', + 'influencer_low_suggestion' + ]); + } + ); + }); + // the following two tests validate the correct template rendering of // urls in messages with {{version}} in them to be replaced with the // specified version. (defaulting to 'current') diff --git a/x-pack/plugins/ml/server/models/job_validation/validate_cardinality.js b/x-pack/plugins/ml/server/models/job_validation/validate_cardinality.js index dc6e4166b0c7..0cee9d888556 100644 --- a/x-pack/plugins/ml/server/models/job_validation/validate_cardinality.js +++ b/x-pack/plugins/ml/server/models/job_validation/validate_cardinality.js @@ -65,10 +65,17 @@ const validateFactory = (callWithRequest, job) => { }); } } else { - messages.push({ - id: 'field_not_aggregatable', - fieldName: uniqueFieldName - }); + // when the job is using categorization and the field name is set to 'mlcategory', + // then don't report the field as not being able to be aggregated. + if (!( + typeof job.analysis_config.categorization_field_name !== 'undefined' && + uniqueFieldName === 'mlcategory' + )) { + messages.push({ + id: 'field_not_aggregatable', + fieldName: uniqueFieldName + }); + } } }); } catch (e) {