diff --git a/x-pack/plugins/ml/public/application/components/data_grid/common.ts b/x-pack/plugins/ml/public/application/components/data_grid/common.ts index 48a0a0c9ab12..909f1ec9ca89 100644 --- a/x-pack/plugins/ml/public/application/components/data_grid/common.ts +++ b/x-pack/plugins/ml/public/application/components/data_grid/common.ts @@ -415,11 +415,20 @@ export const showDataGridColumnChartErrorMessageToast = ( // helper function to transform { [key]: [val] } => { [key]: val } // for when `fields` is used in es.search since response is always an array of values // since response always returns an array of values for each field -export const getProcessedFields = (originalObj: object) => { +export const getProcessedFields = (originalObj: object, omitBy?: (key: string) => boolean) => { const obj: { [key: string]: any } = { ...originalObj }; for (const key of Object.keys(obj)) { - if (Array.isArray(obj[key]) && obj[key].length === 1) { - obj[key] = obj[key][0]; + // if no conditional is included, process everything + if (omitBy === undefined) { + if (Array.isArray(obj[key]) && obj[key].length === 1) { + obj[key] = obj[key][0]; + } + } else { + // else only process the fields for things users don't want to omit + if (omitBy(key) === false) + if (Array.isArray(obj[key]) && obj[key].length === 1) { + obj[key] = obj[key][0]; + } } } return obj; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/common/get_index_data.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/common/get_index_data.ts index 85f222109d40..0f5f48240326 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/common/get_index_data.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/common/get_index_data.ts @@ -63,7 +63,13 @@ export const getIndexData = async ( if (!options.didCancel) { setRowCount(resp.hits.total.value); - setTableItems(resp.hits.hits.map((d) => getProcessedFields(d.fields))); + setTableItems( + resp.hits.hits.map((d) => + getProcessedFields(d.fields, (key: string) => + key.startsWith(`${jobConfig.dest.results_field}.feature_importance`) + ) + ) + ); setStatus(INDEX_STATUS.LOADED); } } catch (e) {