From c597b6cf8d029c9dde44c4c29a5f018bc2cadf0a Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Thu, 22 Aug 2019 11:28:23 +0100 Subject: [PATCH] [ML] Allow index patterns containing commas in recogniser modules (#43686) (#43739) * [ML] Allow index patterns containing commas in recogniser modules * fixing issue where only 'indexes' is the allowed datafeed index list --- .../models/data_recognizer/data_recognizer.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.js b/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.js index 98a8655645a26..b147e83aabeee 100644 --- a/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.js +++ b/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.js @@ -674,9 +674,33 @@ export class DataRecognizer { // if an override index pattern has been specified, // update all of the datafeeds. updateDatafeedIndices(moduleConfig) { + // if the supplied index pattern contains a comma, split into multiple indices and + // add each one to the datafeed + const indexPatternNames = this.indexPatternName.includes(',') + ? this.indexPatternName.split(',').map(i => i.trim()) + : [this.indexPatternName]; + moduleConfig.datafeeds.forEach((df) => { - df.config.indexes = df.config.indexes.map(index => (index === INDEX_PATTERN_NAME ? this.indexPatternName : index)); + const newIndices = []; + // the datafeed can contain indexes and indices + const currentIndices = df.config.indexes !== undefined ? df.config.indexes : df.config.indices; + + currentIndices.forEach(index => { + if (index === INDEX_PATTERN_NAME) { + // the datafeed index is INDEX_PATTERN_NAME, so replace it with index pattern(s) + // supplied by the user or the default one from the manifest + newIndices.push(...indexPatternNames); + } else { + // otherwise keep using the index from the datafeed json + newIndices.push(index); + } + }); + + // just in case indexes was used, delete it in favour of indices + delete df.config.indexes; + df.config.indices = newIndices; }); + moduleConfig.datafeeds; } // loop through the custom urls in each job and replace the INDEX_PATTERN_ID