diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/common/fields.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/common/fields.ts index fb1d4edb37af8..59b42935a141d 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/common/fields.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/common/fields.ts @@ -243,7 +243,8 @@ export function getFlattenedFields(obj: EsDocSource, resultsField: string): EsFi export const getDefaultFieldsFromJobCaps = ( fields: Field[], - jobConfig: DataFrameAnalyticsConfig + jobConfig: DataFrameAnalyticsConfig, + needsDestIndexFields: boolean ): { selectedFields: Field[]; docFields: Field[]; depVarType?: ES_FIELD_TYPES } => { const fieldsObj = { selectedFields: [], docFields: [] }; if (fields.length === 0) { @@ -260,16 +261,22 @@ export const getDefaultFieldsFromJobCaps = ( const predictedField = `${resultsField}.${ predictionFieldName ? predictionFieldName : defaultPredictionField }`; - - const allFields: any = [ - { - id: `${resultsField}.is_training`, - name: `${resultsField}.is_training`, - type: ES_FIELD_TYPES.BOOLEAN, - }, - { id: predictedField, name: predictedField, type }, - ...fields, - ].sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig)); + // Only need to add these first two fields if we didn't use dest index pattern to get the fields + const allFields: any = + needsDestIndexFields === true + ? [ + { + id: `${resultsField}.is_training`, + name: `${resultsField}.is_training`, + type: ES_FIELD_TYPES.BOOLEAN, + }, + { id: predictedField, name: predictedField, type }, + ] + : []; + + allFields.push(...fields); + // @ts-ignore + allFields.sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig)); let selectedFields = allFields .slice(0, DEFAULT_REGRESSION_COLUMNS * 2) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/results_table.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/results_table.tsx index a7f58de1f0c8b..fbdb47c87c7ef 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/results_table.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/results_table.tsx @@ -128,6 +128,8 @@ export const ResultsTable: FC = React.memo( } } + const needsDestIndexFields = indexPattern && indexPattern.title === jobConfig.source.index[0]; + const { errorMessage, loadExploreData, @@ -135,7 +137,14 @@ export const ResultsTable: FC = React.memo( sortDirection, status, tableItems, - } = useExploreData(jobConfig, selectedFields, setSelectedFields, setDocFields, setDepVarType); + } = useExploreData( + jobConfig, + needsDestIndexFields, + selectedFields, + setSelectedFields, + setDocFields, + setDepVarType + ); const columns: Array> = selectedFields .sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig)) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/use_explore_data.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/use_explore_data.ts index ff6d8377508d8..6038def592e5c 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/use_explore_data.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/use_explore_data.ts @@ -51,6 +51,7 @@ export interface UseExploreDataReturnType { export const useExploreData = ( jobConfig: DataFrameAnalyticsConfig | undefined, + needsDestIndexFields: boolean, selectedFields: Field[], setSelectedFields: React.Dispatch>, setDocFields: React.Dispatch>, @@ -70,7 +71,7 @@ export const useExploreData = ( selectedFields: defaultSelected, docFields, depVarType, - } = getDefaultFieldsFromJobCaps(fields, jobConfig); + } = getDefaultFieldsFromJobCaps(fields, jobConfig, needsDestIndexFields); setDepVarType(depVarType); setSelectedFields(defaultSelected); diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/results_table.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/results_table.tsx index f66b9f2126330..8d53a9278a1af 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/results_table.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/results_table.tsx @@ -129,6 +129,8 @@ export const ResultsTable: FC = React.memo( } } + const needsDestIndexFields = indexPattern && indexPattern.title === jobConfig.source.index[0]; + const { errorMessage, loadExploreData, @@ -136,7 +138,14 @@ export const ResultsTable: FC = React.memo( sortDirection, status, tableItems, - } = useExploreData(jobConfig, selectedFields, setSelectedFields, setDocFields, setDepVarType); + } = useExploreData( + jobConfig, + needsDestIndexFields, + selectedFields, + setSelectedFields, + setDocFields, + setDepVarType + ); const columns: Array> = selectedFields .sort(({ name: a }, { name: b }) => sortRegressionResultsFields(a, b, jobConfig)) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/use_explore_data.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/use_explore_data.ts index 22fbbaac99a18..e158e952c1c18 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/use_explore_data.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/regression_exploration/use_explore_data.ts @@ -46,6 +46,7 @@ export interface UseExploreDataReturnType { export const useExploreData = ( jobConfig: DataFrameAnalyticsConfig | undefined, + needsDestIndexFields: boolean, selectedFields: Field[], setSelectedFields: React.Dispatch>, setDocFields: React.Dispatch>, @@ -65,7 +66,7 @@ export const useExploreData = ( selectedFields: defaultSelected, docFields, depVarType, - } = getDefaultFieldsFromJobCaps(fields, jobConfig); + } = getDefaultFieldsFromJobCaps(fields, jobConfig, needsDestIndexFields); setDepVarType(depVarType); setSelectedFields(defaultSelected);