Skip to content

Commit c8852fa

Browse files
committed
[ML] Enabling lat_long agg in advanced wizard
1 parent 7ad6827 commit c8852fa

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/field_service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const supportedTypes: string[] = [
3131
ES_FIELD_TYPES.SCALED_FLOAT,
3232
ES_FIELD_TYPES.SHORT,
3333
ES_FIELD_TYPES.IP,
34+
ES_FIELD_TYPES.GEO_POINT,
35+
ES_FIELD_TYPES.GEO_SHAPE,
3436
];
3537

3638
export function fieldServiceProvider(
@@ -135,24 +137,24 @@ async function combineFieldsAndAggs(
135137
const keywordFields = getKeywordFields(fields);
136138
const numericalFields = getNumericalFields(fields);
137139
const ipFields = getIpFields(fields);
140+
const geoFields = getGeoFields(fields);
138141

139142
const isRollup = Object.keys(rollupFields).length > 0;
140143
const mix = mixFactory(isRollup, rollupFields);
141144

142145
aggs.forEach(a => {
143146
if (a.type === METRIC_AGG_TYPE && a.fields !== undefined) {
144147
switch (a.id) {
148+
case ML_JOB_AGGREGATION.LAT_LONG:
149+
geoFields.forEach(f => mix(f, a));
150+
break;
145151
case ML_JOB_AGGREGATION.DISTINCT_COUNT:
146152
case ML_JOB_AGGREGATION.HIGH_DISTINCT_COUNT:
147153
case ML_JOB_AGGREGATION.LOW_DISTINCT_COUNT:
148154
// distinct count (i.e. cardinality) takes keywords, ips
149155
// as well as numerical fields
150-
keywordFields.forEach(f => {
151-
mix(f, a);
152-
});
153-
ipFields.forEach(f => {
154-
mix(f, a);
155-
});
156+
keywordFields.forEach(f => mix(f, a));
157+
ipFields.forEach(f => mix(f, a));
156158
// note, no break to fall through to add numerical fields.
157159
default:
158160
// all other aggs take numerical fields
@@ -235,3 +237,9 @@ function getNumericalFields(fields: Field[]): Field[] {
235237
f.type === ES_FIELD_TYPES.SCALED_FLOAT
236238
);
237239
}
240+
241+
function getGeoFields(fields: Field[]): Field[] {
242+
return fields.filter(
243+
f => f.type === ES_FIELD_TYPES.GEO_POINT || f.type === ES_FIELD_TYPES.GEO_SHAPE
244+
);
245+
}

0 commit comments

Comments
 (0)