Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.7] [ML] DF Analytics - ensure destination index pattern created (#62450) #62518

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/util/es_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function isValidIndexNameLength(indexName: string) {
// https://github.com/elastic/elasticsearch/blob/master/docs/reference/indices/create-index.asciidoc
export function isValidIndexName(indexName: string) {
return (
typeof indexName === 'string' &&
// Lowercase only
indexName === indexName.toLowerCase() &&
// Cannot include \, /, *, ?, ", <, >, |, space character, comma, #, :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ export const validateAdvancedEditor = (state: State): State => {
),
message: '',
});
} else if (destinationIndexPatternTitleExists && !createIndexPattern) {
state.advancedEditorMessages.push({
error: i18n.translate(
'xpack.ml.dataframe.analytics.create.advancedEditorMessage.destinationIndexNameExistsWarn',
{
defaultMessage:
'An index with this destination index name already exists. Be aware that running this analytics job will modify this destination index.',
}
),
message: '',
});
} else if (!destinationIndexNameValid) {
state.advancedEditorMessages.push({
error: i18n.translate(
Expand Down Expand Up @@ -276,6 +287,8 @@ export const validateAdvancedEditor = (state: State): State => {
});
}

state.form.destinationIndexPatternTitleExists = destinationIndexPatternTitleExists;

state.isValid =
maxDistinctValuesError === undefined &&
excludesValid &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => {
const { refresh } = useRefreshAnalyticsList();

const { form, jobConfig, isAdvancedEditorEnabled } = state;
const { createIndexPattern, destinationIndex, jobId } = form;
const { createIndexPattern, jobId } = form;
let { destinationIndex } = form;

const addRequestMessage = (requestMessage: FormMessage) =>
dispatch({ type: ACTION.ADD_REQUEST_MESSAGE, requestMessage });
Expand Down Expand Up @@ -90,9 +91,13 @@ export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => {
resetRequestMessages();
setIsModalButtonDisabled(true);

const analyticsJobConfig = isAdvancedEditorEnabled
const analyticsJobConfig = (isAdvancedEditorEnabled
? jobConfig
: getJobConfigFromFormState(form);
: getJobConfigFromFormState(form)) as DataFrameAnalyticsConfig;

if (isAdvancedEditorEnabled) {
destinationIndex = analyticsJobConfig.dest.index;
}

try {
await ml.dataFrameAnalytics.createDataFrameAnalytics(jobId, analyticsJobConfig);
Expand Down