From 10b5b915e9e4be729c652f081a95662d31c7b375 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 2 Aug 2017 08:53:02 -0700 Subject: [PATCH] Turn filter editor suggestions on by default --- docs/discover/field-filter.asciidoc | 7 ++-- docs/management/advanced-options.asciidoc | 2 +- .../suggestions/register_value_suggestions.js | 36 +++++++++++-------- .../kibana/ui_setting_defaults.js | 8 ++--- .../filter_params_phrase_controller.js | 7 ++-- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/docs/discover/field-filter.asciidoc b/docs/discover/field-filter.asciidoc index e9b05f6a0fbe8..18d8cbfaabb2f 100644 --- a/docs/discover/field-filter.asciidoc +++ b/docs/discover/field-filter.asciidoc @@ -70,9 +70,10 @@ displayed below the query bar instead of the filter definition. . Click *Save*. The filter will be applied to your search and be displayed below the query bar. -NOTE: To make the filter editor more user-friendly, you can enable the `filterEditor:suggestValues` advanced setting. -Enabling this will cause the editor to suggest values from your indices if you are filtering against an aggregatable -field. However, this is not recommended for extremely large datasets, as it can result in long queries. +NOTE: By default, the filter editor will suggest values for fields that are aggregatable. If this +results in long-running requests, you can configure the `filterEditor:suggestions:terminateAfter` +advanced setting. Setting it to a lower value will result in quicker requests but may also result +in less helpful suggestions. Setting it to `0` will disable suggestions completely. [float] [[filter-pinning]] diff --git a/docs/management/advanced-options.asciidoc b/docs/management/advanced-options.asciidoc index f601e097dc287..854bc27d7b74d 100644 --- a/docs/management/advanced-options.asciidoc +++ b/docs/management/advanced-options.asciidoc @@ -75,7 +75,7 @@ mentioned use "_default_". `timepicker:refreshIntervalDefaults`:: The time filter's default refresh interval. `dashboard:defaultDarkTheme`:: Set this property to `true` to make new dashboards use the dark theme by default. `filters:pinnedByDefault`:: Set this property to `true` to make filters have a global state by default. -`filterEditor:suggestValues`:: Set this property to `true` to have the filter editor suggest values for fields, instead of just providing a text input. This may result in heavy queries to Elasticsearch. +`filterEditor:suggestions:terminateAfter`:: By default, the filter editor will suggest values for aggregatable fields. Setting this to a lower value will make the request for aggregatable fields quicker, yet may result in fewer suggestions. Set to `0` to disable suggestions entirely. `notifications:banner`:: You can specify a custom banner to display temporary notices to all users. This field supports Markdown. `notifications:lifetime:banner`:: Specifies the duration in milliseconds for banner notification displays. The default value is 3000000. Set this field to `Infinity` to disable banner notifications. diff --git a/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js b/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js index 4e7c85a069227..ec850248fa202 100644 --- a/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js +++ b/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js @@ -4,33 +4,39 @@ export function registerValueSuggestions(server) { server.route({ path: '/api/kibana/suggestions/values/{index}', method: ['POST'], - handler: function (req, reply) { + handler: async function (req, reply) { + const uiSettings = req.getUiSettingsService(); const { index } = req.params; const { field, query } = req.payload; + const terminateAfter = await uiSettings.get('filterEditor:suggestions:terminateAfter'); const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); - const include = query ? `.*${query}.*` : undefined; - const body = getBody({ - field, - include, - shard_size: 10, - size: 10 - }); + const body = getBody({ field, query, terminateAfter }); - return callWithRequest(req, 'search', { index, body }) - .then((res) => { - const suggestions = res.aggregations.suggestions.buckets.map(bucket => bucket.key); + try { + const response = await callWithRequest(req, 'search', { index, body }); + const suggestions = response.aggregations.suggestions.buckets.map(bucket => bucket.key); return reply(suggestions); - }) - .catch(error => reply(handleESError(error))); + } catch (error) { + return reply(handleESError(error)); + } } }); } -function getBody(terms) { +function getBody({ field, query, terminateAfter }) { + const include = query ? `.*${query}.*` : undefined; return { + size: 0, + terminate_after: terminateAfter, aggs: { - suggestions: { terms } + suggestions: { + terms: { + field, + include, + execution_hint: 'map' + } + } } }; } diff --git a/src/core_plugins/kibana/ui_setting_defaults.js b/src/core_plugins/kibana/ui_setting_defaults.js index 14b112dcd4e6b..cfd88f8e22ef4 100644 --- a/src/core_plugins/kibana/ui_setting_defaults.js +++ b/src/core_plugins/kibana/ui_setting_defaults.js @@ -269,10 +269,10 @@ export function getUiSettingDefaults() { value: false, description: 'Whether the filters should have a global state (be pinned) by default' }, - 'filterEditor:suggestValues': { - value: false, - description: 'Set this property to `true` to have the filter editor suggest values for fields, ' + - 'instead of just providing a text input. This may result in heavy queries to Elasticsearch.' + 'filterEditor:suggestions:terminateAfter': { + value: 10000, + description: 'By default, the filter editor will suggest values for aggregatable fields. Setting this to a lower value will make the' + + 'request for aggregatable fields quicker, yet may result in fewer suggestions. Set to `0` to disable suggestions entirely.' }, 'notifications:banner': { type: 'markdown', diff --git a/src/ui/public/filter_editor/params_editor/filter_params_phrase_controller.js b/src/ui/public/filter_editor/params_editor/filter_params_phrase_controller.js index f92e3a5806912..748b40eb1fb0f 100644 --- a/src/ui/public/filter_editor/params_editor/filter_params_phrase_controller.js +++ b/src/ui/public/filter_editor/params_editor/filter_params_phrase_controller.js @@ -4,12 +4,9 @@ import chrome from 'ui/chrome'; const baseUrl = chrome.addBasePath('/api/kibana/suggestions/values'); export function filterParamsPhraseController($http, $scope, config) { - const shouldSuggestValues = this.shouldSuggestValues = config.get('filterEditor:suggestValues'); - + const shouldSuggestValues = this.shouldSuggestValues = (config.get('filterEditor:suggestions:terminateAfter') !== 0); this.compactUnion = _.flow(_.union, _.compact); - this.getValueSuggestions = _.memoize(getValueSuggestions, getFieldQueryHash); - this.refreshValueSuggestions = (query) => { return this.getValueSuggestions($scope.field, query) .then(suggestions => $scope.valueSuggestions = suggestions); @@ -32,7 +29,7 @@ export function filterParamsPhraseController($http, $scope, config) { .catch(() => []); } - function getFieldQueryHash(field, query) { + function getFieldQueryHash(field, query = '') { return `${field.indexPattern.id}/${field.name}/${query}`; } }