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

Turn filter editor suggestions back on by default #13286

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 4 additions & 3 deletions docs/discover/field-filter.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
2 changes: 1 addition & 1 deletion docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
};
}
8 changes: 4 additions & 4 deletions src/core_plugins/kibana/ui_setting_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}`;
}
}