From 2b284395c86298d95d7b2d35ec30e1175551b2b9 Mon Sep 17 00:00:00 2001 From: Pete Harverson Date: Tue, 11 Dec 2018 15:30:41 +0000 Subject: [PATCH] [ML] Do not pass datafeed query to Discover in custom URL (#26957) --- .../jobs/components/custom_url_editor/utils.js | 18 +++++++----------- .../edit_job_flyout/tabs/custom_urls.js | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js b/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js index 08766835c73b2..b10277ec8979f 100644 --- a/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js +++ b/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js @@ -113,13 +113,13 @@ export function isValidCustomUrlSettings(settings, savedCustomUrls) { return isValid; } -export function buildCustomUrlFromSettings(settings, job) { +export function buildCustomUrlFromSettings(settings) { // Dashboard URL returns a Promise as a query is made to obtain the full dashboard config. // So wrap the other two return types in a Promise for consistent return type. if (settings.type === URL_TYPE.KIBANA_DASHBOARD) { return buildDashboardUrlFromSettings(settings); } else if (settings.type === URL_TYPE.KIBANA_DISCOVER) { - return Promise.resolve(buildDiscoverUrlFromSettings(settings, job)); + return Promise.resolve(buildDiscoverUrlFromSettings(settings)); } else { const urlToAdd = { url_name: settings.label, @@ -219,7 +219,7 @@ function buildDashboardUrlFromSettings(settings) { } -function buildDiscoverUrlFromSettings(settings, job) { +function buildDiscoverUrlFromSettings(settings) { const { discoverIndexPatternId, queryFieldNames } = settings.kibanaSettings; // Add time settings to the global state URL parameter with $earliest$ and @@ -238,10 +238,10 @@ function buildDiscoverUrlFromSettings(settings, job) { index: discoverIndexPatternId }; - // Use the query from the datafeed only if no job entities are selected. - let query = job.datafeed_config.query; + // If partitioning field entities have been configured add tokens + // to the URL to use in the Discover page search. - // To put entities in filters section would involve creating parameters of the form + // Ideally we would put entities in the filters section, but currently this involves creating parameters of the form // filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:b30fd340-efb4-11e7-a600-0f58b1422b87, // key:airline,negate:!f,params:(query:AAL,type:phrase),type:phrase,value:AAL),query:(match:(airline:(query:AAL,type:phrase))))) // which includes the ID of the index holding the field used in the filter. @@ -257,16 +257,12 @@ function buildDiscoverUrlFromSettings(settings, job) { queryString += `${escapeForElasticsearchQuery(fieldName)}:"$${fieldName}$"`; }); - query = { + appState.query = { language: 'lucene', query: queryString }; } - if (query !== undefined) { - appState.query = query; - } - const _a = rison.encode(appState); const urlValue = `kibana#/discover?_g=${_g}&_a=${_a}`; diff --git a/x-pack/plugins/ml/public/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.js b/x-pack/plugins/ml/public/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.js index 49964514a21fa..c70cb61bd9d46 100644 --- a/x-pack/plugins/ml/public/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.js +++ b/x-pack/plugins/ml/public/jobs/jobs_list/components/edit_job_flyout/tabs/custom_urls.js @@ -113,7 +113,7 @@ class CustomUrlsUI extends Component { } addNewCustomUrl = () => { - buildCustomUrlFromSettings(this.state.editorSettings, this.props.job) + buildCustomUrlFromSettings(this.state.editorSettings) .then((customUrl) => { const customUrls = [...this.state.customUrls, customUrl]; this.setCustomUrls(customUrls); @@ -131,7 +131,7 @@ class CustomUrlsUI extends Component { onTestButtonClick = () => { const job = this.props.job; const { intl } = this.props; - buildCustomUrlFromSettings(this.state.editorSettings, job) + buildCustomUrlFromSettings(this.state.editorSettings) .then((customUrl) => { getTestUrl(job, customUrl) .then((testUrl) => {