Skip to content

Commit

Permalink
[ML] Fixes field formatter used for chart and anomaly table values
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Oct 23, 2019
1 parent 3b6c2b6 commit 714d6f6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions x-pack/legacy/plugins/ml/public/services/field_format_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ class FieldFormatService {
// e.g. distinct_count(clientip) should be formatted as a count, not as an IP address.
let fieldFormat = undefined;
if (esAggName !== 'cardinality') {
const indexPatternFields = _.get(fullIndexPattern, 'fields', []);
fieldFormat = _.get(indexPatternFields, [fieldName, 'format']);
const fieldList = _.get(fullIndexPattern, 'fields', []);
const field = fieldList.getByName(fieldName);
if (field !== undefined) {
fieldFormat = field.format;
}
}

return fieldFormat;
Expand All @@ -99,13 +102,16 @@ class FieldFormatService {
getIndexPatternById(indexPatternId)
.then((indexPatternData) => {
// Store the FieldFormat for each job by detector_index.
const fieldsByName = _.get(indexPatternData, 'fields', []);
const fieldList = _.get(indexPatternData, 'fields', []);
_.each(detectors, (dtr) => {
const esAgg = mlFunctionToESAggregation(dtr.function);
// distinct_count detectors should fall back to the default
// formatter as the values are just counts.
if (dtr.field_name !== undefined && esAgg !== 'cardinality') {
formatsByDetector[dtr.detector_index] = _.get(fieldsByName, [dtr.field_name, 'format']);
const field = fieldList.getByName(dtr.field_name);
if (field !== undefined) {
formatsByDetector[dtr.detector_index] = field.format;
}
}
});

Expand Down

0 comments on commit 714d6f6

Please sign in to comment.