Skip to content

Commit b5cc13c

Browse files
[ML] Fix categorization job view examples link when datafeed uses multiple indices (#100789)
* [ML] Fix categorization job view examples link when datafeed uses multiple indices * [ML] Fix operator in index pattern check Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 228cc94 commit b5cc13c

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

  • x-pack/plugins/ml/public/application

x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class LinksMenuUI extends Component {
232232
}
233233
const categorizationFieldName = job.analysis_config.categorization_field_name;
234234
const datafeedIndices = job.datafeed_config.indices;
235+
235236
// Find the type of the categorization field i.e. text (preferred) or keyword.
236237
// Uses the first matching field found in the list of indices in the datafeed_config.
237238
// attempt to load the field type using each index. we have to do it this way as _field_caps
@@ -349,7 +350,7 @@ class LinksMenuUI extends Component {
349350
getFieldTypeFromMapping(index, categorizationFieldName)
350351
.then((resp) => {
351352
if (resp !== '') {
352-
createAndOpenUrl(index, resp);
353+
createAndOpenUrl(datafeedIndices.join(), resp);
353354
} else {
354355
i++;
355356
if (i < datafeedIndices.length) {

x-pack/plugins/ml/public/application/jobs/components/custom_url_editor/utils.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DASHBOARD_APP_URL_GENERATOR } from '../../../../../../../../src/plugins
1515
import { getPartitioningFieldNames } from '../../../../../common/util/job_utils';
1616
import { parseInterval } from '../../../../../common/util/parse_interval';
1717
import { replaceTokensInUrlValue, isValidLabel } from '../../../util/custom_url_utils';
18+
import { getIndexPatternIdFromName } from '../../../util/index_utils';
1819
import { ml } from '../../../services/ml_api_service';
1920
import { mlJobService } from '../../../services/job_service';
2021
import { escapeForElasticsearchQuery } from '../../../util/string_utils';
@@ -38,7 +39,7 @@ export function getNewCustomUrlDefaults(job, dashboards, indexPatterns) {
3839
}
3940

4041
// For the Discover option, set the default index pattern to that
41-
// which matches the (first) index configured in the job datafeed.
42+
// which matches the indices configured in the job datafeed.
4243
const datafeedConfig = job.datafeed_config;
4344
if (
4445
indexPatterns !== undefined &&
@@ -47,16 +48,9 @@ export function getNewCustomUrlDefaults(job, dashboards, indexPatterns) {
4748
datafeedConfig.indices !== undefined &&
4849
datafeedConfig.indices.length > 0
4950
) {
50-
const datafeedIndex = datafeedConfig.indices[0];
51-
let defaultIndexPattern = indexPatterns.find((indexPattern) => {
52-
return indexPattern.title === datafeedIndex;
53-
});
54-
55-
if (defaultIndexPattern === undefined) {
56-
defaultIndexPattern = indexPatterns[0];
57-
}
58-
59-
kibanaSettings.discoverIndexPatternId = defaultIndexPattern.id;
51+
const defaultIndexPatternId =
52+
getIndexPatternIdFromName(datafeedConfig.indices.join()) ?? indexPatterns[0].id;
53+
kibanaSettings.discoverIndexPatternId = defaultIndexPatternId;
6054
}
6155

6256
return {

0 commit comments

Comments
 (0)