From 8293684b09e85784ab19fbf8624a71db1dad9ae2 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Tue, 31 Mar 2020 13:59:57 -0400 Subject: [PATCH] [ML] DF Analytics results table: use index pattern field format if one exists (#61709) (#61989) * classification: use index field format in results table * regression: use index field format in results table * outlier: use index field format in results table * update types * add destIndex specific fields when using sourceIndex for fields --- .../data_frame_analytics/common/fields.ts | 29 ++++++----- .../classification_exploration.tsx | 49 +++++++++++++------ .../results_table.tsx | 43 ++++++++++++---- .../use_explore_data.ts | 3 +- .../exploration_data_grid.tsx | 16 ++++++ .../outlier_exploration.tsx | 1 + .../regression_exploration.tsx | 47 +++++++++++++----- .../regression_exploration/results_table.tsx | 43 +++++++++++++--- .../use_explore_data.ts | 3 +- .../use_explore_data/use_explore_data.ts | 32 +++++++++--- 10 files changed, 203 insertions(+), 63 deletions(-) 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/classification_exploration.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/classification_exploration.tsx index 41430b163c029..5c151166829ab 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/classification_exploration.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/classification_exploration/classification_exploration.tsx @@ -15,7 +15,7 @@ import { DATA_FRAME_TASK_STATE } from '../../../analytics_management/components/ import { ResultsSearchQuery, defaultSearchQuery } from '../../../../common/analytics'; import { LoadingPanel } from '../loading_panel'; import { getIndexPatternIdFromName } from '../../../../../util/index_utils'; -import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/common/index_patterns'; +import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public'; import { newJobCapsService } from '../../../../../services/new_job_capabilities_service'; import { useMlContext } from '../../../../../contexts/ml'; import { isGetDataFrameAnalyticsStatsResponseOk } from '../../../analytics_management/services/analytics_service/get_analytics'; @@ -53,6 +53,7 @@ interface Props { export const ClassificationExploration: FC = ({ jobId }) => { const [jobConfig, setJobConfig] = useState(undefined); const [jobStatus, setJobStatus] = useState(undefined); + const [indexPattern, setIndexPattern] = useState(undefined); const [isLoadingJobConfig, setIsLoadingJobConfig] = useState(false); const [isInitialized, setIsInitialized] = useState(false); const [jobConfigErrorMessage, setJobConfigErrorMessage] = useState(undefined); @@ -108,11 +109,27 @@ export const ClassificationExploration: FC = ({ jobId }) => { const initializeJobCapsService = async () => { if (jobConfig !== undefined) { try { - const sourceIndex = jobConfig.source.index[0]; - const indexPatternId = getIndexPatternIdFromName(sourceIndex) || sourceIndex; - const indexPattern: IIndexPattern = await mlContext.indexPatterns.get(indexPatternId); - if (indexPattern !== undefined) { - await newJobCapsService.initializeFromIndexPattern(indexPattern, false, false); + const destIndex = Array.isArray(jobConfig.dest.index) + ? jobConfig.dest.index[0] + : jobConfig.dest.index; + const destIndexPatternId = getIndexPatternIdFromName(destIndex) || destIndex; + let indexP: IndexPattern | undefined; + + try { + indexP = await mlContext.indexPatterns.get(destIndexPatternId); + } catch (e) { + indexP = undefined; + } + + if (indexP === undefined) { + const sourceIndex = jobConfig.source.index[0]; + const sourceIndexPatternId = getIndexPatternIdFromName(sourceIndex) || sourceIndex; + indexP = await mlContext.indexPatterns.get(sourceIndexPatternId); + } + + if (indexP !== undefined) { + setIndexPattern(indexP); + await newJobCapsService.initializeFromIndexPattern(indexP, false, false); } setIsInitialized(true); } catch (e) { @@ -127,7 +144,7 @@ export const ClassificationExploration: FC = ({ jobId }) => { useEffect(() => { initializeJobCapsService(); - }, [JSON.stringify(jobConfig)]); + }, [jobConfig && jobConfig.id]); if (jobConfigErrorMessage !== undefined || jobCapsServiceErrorMessage !== undefined) { return ( @@ -153,13 +170,17 @@ export const ClassificationExploration: FC = ({ jobId }) => { )} {isLoadingJobConfig === true && jobConfig === undefined && } - {isLoadingJobConfig === false && jobConfig !== undefined && isInitialized === true && ( - - )} + {isLoadingJobConfig === false && + jobConfig !== undefined && + indexPattern !== undefined && + isInitialized === true && ( + + )} ); }; 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 dabb8db514226..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 @@ -28,6 +28,8 @@ import { import { Query as QueryType } from '../../../analytics_management/components/analytics_list/common'; import { ES_FIELD_TYPES } from '../../../../../../../../../../src/plugins/data/public'; +import { mlFieldFormatService } from '../../../../../services/field_format_service'; +import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public'; import { ColumnType, @@ -61,7 +63,6 @@ import { } from '../../../../common'; import { getTaskStateBadge } from '../../../analytics_management/components/analytics_list/columns'; import { DATA_FRAME_TASK_STATE } from '../../../analytics_management/components/analytics_list/common'; - import { useExploreData, TableItem } from './use_explore_data'; import { ExplorationTitle } from './classification_exploration'; @@ -85,13 +86,14 @@ const showingFirstDocs = i18n.translate( ); interface Props { + indexPattern: IndexPattern; jobConfig: DataFrameAnalyticsConfig; jobStatus?: DATA_FRAME_TASK_STATE; setEvaluateSearchQuery: React.Dispatch>; } export const ResultsTable: FC = React.memo( - ({ jobConfig, jobStatus, setEvaluateSearchQuery }) => { + ({ indexPattern, jobConfig, jobStatus, setEvaluateSearchQuery }) => { const [pageIndex, setPageIndex] = useState(0); const [pageSize, setPageSize] = useState(25); const [selectedFields, setSelectedFields] = useState([] as Field[]); @@ -126,6 +128,8 @@ export const ResultsTable: FC = React.memo( } } + const needsDestIndexFields = indexPattern && indexPattern.title === jobConfig.source.index[0]; + const { errorMessage, loadExploreData, @@ -133,12 +137,24 @@ 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)) .map(field => { const { type } = field; + let format: any; + + if (indexPattern !== undefined) { + format = mlFieldFormatService.getFieldFormatFromIndexPattern(indexPattern, field.id, ''); + } const isNumber = type !== undefined && (BASIC_NUMERICAL_TYPES.has(type) || EXTENDED_NUMERICAL_TYPES.has(type)); @@ -151,6 +167,11 @@ export const ResultsTable: FC = React.memo( }; const render = (d: any, fullItem: EsDoc) => { + if (format !== undefined) { + d = format.convert(d, 'text'); + return d; + } + if (Array.isArray(d) && d.every(item => typeof item === 'string')) { // If the cells data is an array of strings, return as a comma separated list. // The list will get limited to 5 items with `…` at the end if there's more in the original array. @@ -193,12 +214,16 @@ export const ResultsTable: FC = React.memo( break; case ES_FIELD_TYPES.DATE: column.align = 'right'; - column.render = (d: any) => { - if (d !== undefined) { - return formatHumanReadableDateTimeSeconds(moment(d).unix() * 1000); - } - return d; - }; + if (format !== undefined) { + column.render = render; + } else { + column.render = (d: any) => { + if (d !== undefined) { + return formatHumanReadableDateTimeSeconds(moment(d).unix() * 1000); + } + return d; + }; + } break; default: column.render = render; 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/exploration_data_grid/exploration_data_grid.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_data_grid/exploration_data_grid.tsx index 2df0f70a56722..e88bc1cd06f95 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_data_grid/exploration_data_grid.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_data_grid/exploration_data_grid.tsx @@ -12,6 +12,10 @@ import { EuiDataGrid, EuiDataGridPaginationProps, EuiDataGridSorting } from '@el import { euiDataGridStyle, euiDataGridToolbarSettings } from '../../../../common'; +import { mlFieldFormatService } from '../../../../../services/field_format_service'; + +import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public'; + const FEATURE_INFLUENCE = 'feature_influence'; const PAGE_SIZE_OPTIONS = [5, 10, 25, 50]; @@ -21,6 +25,7 @@ type TableItem = Record; interface ExplorationDataGridProps { colorRange: (d: number) => string; columns: any[]; + indexPattern: IndexPattern; pagination: Pagination; resultsField: string; rowCount: number; @@ -35,6 +40,7 @@ interface ExplorationDataGridProps { export const ExplorationDataGrid: FC = ({ colorRange, columns, + indexPattern, pagination, resultsField, rowCount, @@ -63,6 +69,12 @@ export const ExplorationDataGrid: FC = ({ return null; } + let format: any; + + if (indexPattern !== undefined) { + format = mlFieldFormatService.getFieldFormatFromIndexPattern(indexPattern, columnId, ''); + } + const cellValue = fullItem.hasOwnProperty(columnId) && fullItem[columnId] !== undefined ? fullItem[columnId] @@ -87,6 +99,10 @@ export const ExplorationDataGrid: FC = ({ }); } + if (format !== undefined) { + return format.convert(cellValue, 'text'); + } + if (typeof cellValue === 'string' || cellValue === null) { return cellValue; } diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx index d686c605f1912..fdcb7d9d237e3 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx @@ -203,6 +203,7 @@ export const OutlierExploration: FC = React.memo(({ jobId }) = = ({ jobId }) => { const [jobConfig, setJobConfig] = useState(undefined); const [jobStatus, setJobStatus] = useState(undefined); + const [indexPattern, setIndexPattern] = useState(undefined); const [isLoadingJobConfig, setIsLoadingJobConfig] = useState(false); const [isInitialized, setIsInitialized] = useState(false); const [jobConfigErrorMessage, setJobConfigErrorMessage] = useState(undefined); @@ -99,11 +100,27 @@ export const RegressionExploration: FC = ({ jobId }) => { const initializeJobCapsService = async () => { if (jobConfig !== undefined) { try { - const sourceIndex = jobConfig.source.index[0]; - const indexPatternId = getIndexPatternIdFromName(sourceIndex) || sourceIndex; - const indexPattern: IIndexPattern = await mlContext.indexPatterns.get(indexPatternId); - if (indexPattern !== undefined) { - await newJobCapsService.initializeFromIndexPattern(indexPattern, false, false); + const destIndex = Array.isArray(jobConfig.dest.index) + ? jobConfig.dest.index[0] + : jobConfig.dest.index; + const destIndexPatternId = getIndexPatternIdFromName(destIndex) || destIndex; + let indexP: IIndexPattern | undefined; + + try { + indexP = await mlContext.indexPatterns.get(destIndexPatternId); + } catch (e) { + indexP = undefined; + } + + if (indexP === undefined) { + const sourceIndex = jobConfig.source.index[0]; + const sourceIndexPatternId = getIndexPatternIdFromName(sourceIndex) || sourceIndex; + indexP = await mlContext.indexPatterns.get(sourceIndexPatternId); + } + + if (indexP !== undefined) { + setIndexPattern(indexP); + await newJobCapsService.initializeFromIndexPattern(indexP, false, false); } setIsInitialized(true); } catch (e) { @@ -118,7 +135,7 @@ export const RegressionExploration: FC = ({ jobId }) => { useEffect(() => { initializeJobCapsService(); - }, [JSON.stringify(jobConfig)]); + }, [jobConfig && jobConfig.id]); if (jobConfigErrorMessage !== undefined || jobCapsServiceErrorMessage !== undefined) { return ( @@ -144,13 +161,17 @@ export const RegressionExploration: FC = ({ jobId }) => { )} {isLoadingJobConfig === true && jobConfig === undefined && } - {isLoadingJobConfig === false && jobConfig !== undefined && isInitialized === true && ( - - )} + {isLoadingJobConfig === false && + jobConfig !== undefined && + indexPattern !== undefined && + isInitialized === true && ( + + )} ); }; 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 b896c34a582f7..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 @@ -28,6 +28,7 @@ import { import { Query as QueryType } from '../../../analytics_management/components/analytics_list/common'; import { ES_FIELD_TYPES } from '../../../../../../../../../../src/plugins/data/public'; +import { mlFieldFormatService } from '../../../../../services/field_format_service'; import { ColumnType, @@ -61,6 +62,7 @@ import { } from '../../../../common'; import { getTaskStateBadge } from '../../../analytics_management/components/analytics_list/columns'; import { DATA_FRAME_TASK_STATE } from '../../../analytics_management/components/analytics_list/common'; +import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public'; import { useExploreData, TableItem } from './use_explore_data'; import { ExplorationTitle } from './regression_exploration'; @@ -85,13 +87,14 @@ const showingFirstDocs = i18n.translate( ); interface Props { + indexPattern: IndexPattern; jobConfig: DataFrameAnalyticsConfig; jobStatus?: DATA_FRAME_TASK_STATE; setEvaluateSearchQuery: React.Dispatch>; } export const ResultsTable: FC = React.memo( - ({ jobConfig, jobStatus, setEvaluateSearchQuery }) => { + ({ indexPattern, jobConfig, jobStatus, setEvaluateSearchQuery }) => { const [pageIndex, setPageIndex] = useState(0); const [pageSize, setPageSize] = useState(25); const [selectedFields, setSelectedFields] = useState([] as Field[]); @@ -126,6 +129,8 @@ export const ResultsTable: FC = React.memo( } } + const needsDestIndexFields = indexPattern && indexPattern.title === jobConfig.source.index[0]; + const { errorMessage, loadExploreData, @@ -133,12 +138,25 @@ 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)) .map(field => { const { type } = field; + let format: any; + + if (indexPattern !== undefined) { + format = mlFieldFormatService.getFieldFormatFromIndexPattern(indexPattern, field.id, ''); + } + const isNumber = type !== undefined && (BASIC_NUMERICAL_TYPES.has(type) || EXTENDED_NUMERICAL_TYPES.has(type)); @@ -151,6 +169,11 @@ export const ResultsTable: FC = React.memo( }; const render = (d: any, fullItem: EsDoc) => { + if (format !== undefined) { + d = format.convert(d, 'text'); + return d; + } + if (Array.isArray(d) && d.every(item => typeof item === 'string')) { // If the cells data is an array of strings, return as a comma separated list. // The list will get limited to 5 items with `…` at the end if there's more in the original array. @@ -193,12 +216,16 @@ export const ResultsTable: FC = React.memo( break; case ES_FIELD_TYPES.DATE: column.align = 'right'; - column.render = (d: any) => { - if (d !== undefined) { - return formatHumanReadableDateTimeSeconds(moment(d).unix() * 1000); - } - return d; - }; + if (format !== undefined) { + column.render = render; + } else { + column.render = (d: any) => { + if (d !== undefined) { + return formatHumanReadableDateTimeSeconds(moment(d).unix() * 1000); + } + return d; + }; + } break; default: column.render = render; 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); diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/hooks/use_explore_data/use_explore_data.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/hooks/use_explore_data/use_explore_data.ts index d637057a4430d..30f2139a263f7 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/hooks/use_explore_data/use_explore_data.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/hooks/use_explore_data/use_explore_data.ts @@ -116,12 +116,32 @@ export const useExploreData = (jobId: string): UseExploreDataReturnType => { useEffect(() => { (async () => { if (jobConfig !== undefined) { - const sourceIndex = jobConfig.source.index[0]; - const indexPatternId = getIndexPatternIdFromName(sourceIndex) || sourceIndex; - const jobCapsIndexPattern: IndexPattern = await mlContext.indexPatterns.get(indexPatternId); - if (jobCapsIndexPattern !== undefined) { - setIndexPattern(jobCapsIndexPattern); - await newJobCapsService.initializeFromIndexPattern(jobCapsIndexPattern, false, false); + try { + const destIndex = Array.isArray(jobConfig.dest.index) + ? jobConfig.dest.index[0] + : jobConfig.dest.index; + const destIndexPatternId = getIndexPatternIdFromName(destIndex) || destIndex; + let indexP: IndexPattern | undefined; + + try { + indexP = await mlContext.indexPatterns.get(destIndexPatternId); + } catch (e) { + indexP = undefined; + } + + if (indexP === undefined) { + const sourceIndex = jobConfig.source.index[0]; + const sourceIndexPatternId = getIndexPatternIdFromName(sourceIndex) || sourceIndex; + indexP = await mlContext.indexPatterns.get(sourceIndexPatternId); + } + + if (indexP !== undefined) { + setIndexPattern(indexP); + await newJobCapsService.initializeFromIndexPattern(indexP, false, false); + } + } catch (e) { + // eslint-disable-next-line + console.log('Error loading index field data', e); } } })();