From 3407f4f06c8320e06451a45d4ca4bdc3ffde46cc Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Mon, 18 Nov 2019 10:31:39 +0000 Subject: [PATCH] [ML] Enabling lat_long detector function in advanced wizard (#50787) * [ML] Enabling lat_long agg in advanced wizard * fixing tests --- .../__mocks__/results/farequote_job_caps.json | 7 ++----- .../job_service/new_job_caps/field_service.ts | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/__mocks__/results/farequote_job_caps.json b/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/__mocks__/results/farequote_job_caps.json index 99c373eddd107..c005d9a5b5aaa 100644 --- a/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/__mocks__/results/farequote_job_caps.json +++ b/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/__mocks__/results/farequote_job_caps.json @@ -460,9 +460,7 @@ "max": "max", "min": "min" }, - "fieldIds": [ - "responsetime" - ] + "fieldIds": [] } ], "fields": [ @@ -513,8 +511,7 @@ "low_non_null_sum", "info_content", "high_info_content", - "low_info_content", - "lat_long" + "low_info_content" ] } ] diff --git a/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/field_service.ts b/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/field_service.ts index 32309ad8177f4..d53d5344adb64 100644 --- a/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/field_service.ts +++ b/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/field_service.ts @@ -31,6 +31,8 @@ const supportedTypes: string[] = [ ES_FIELD_TYPES.SCALED_FLOAT, ES_FIELD_TYPES.SHORT, ES_FIELD_TYPES.IP, + ES_FIELD_TYPES.GEO_POINT, + ES_FIELD_TYPES.GEO_SHAPE, ]; export function fieldServiceProvider( @@ -135,6 +137,7 @@ async function combineFieldsAndAggs( const keywordFields = getKeywordFields(fields); const numericalFields = getNumericalFields(fields); const ipFields = getIpFields(fields); + const geoFields = getGeoFields(fields); const isRollup = Object.keys(rollupFields).length > 0; const mix = mixFactory(isRollup, rollupFields); @@ -142,17 +145,16 @@ async function combineFieldsAndAggs( aggs.forEach(a => { if (a.type === METRIC_AGG_TYPE && a.fields !== undefined) { switch (a.id) { + case ML_JOB_AGGREGATION.LAT_LONG: + geoFields.forEach(f => mix(f, a)); + break; case ML_JOB_AGGREGATION.DISTINCT_COUNT: case ML_JOB_AGGREGATION.HIGH_DISTINCT_COUNT: case ML_JOB_AGGREGATION.LOW_DISTINCT_COUNT: // distinct count (i.e. cardinality) takes keywords, ips // as well as numerical fields - keywordFields.forEach(f => { - mix(f, a); - }); - ipFields.forEach(f => { - mix(f, a); - }); + keywordFields.forEach(f => mix(f, a)); + ipFields.forEach(f => mix(f, a)); // note, no break to fall through to add numerical fields. default: // all other aggs take numerical fields @@ -235,3 +237,9 @@ function getNumericalFields(fields: Field[]): Field[] { f.type === ES_FIELD_TYPES.SCALED_FLOAT ); } + +function getGeoFields(fields: Field[]): Field[] { + return fields.filter( + f => f.type === ES_FIELD_TYPES.GEO_POINT || f.type === ES_FIELD_TYPES.GEO_SHAPE + ); +}