Skip to content

Commit

Permalink
Check sort:options for Discover default sort order (#13708) (#13764)
Browse files Browse the repository at this point in the history
* Check sort:options for Discover default sort order

I went back and forth on a lot of different solutions for this.

Initially I thought it would make sense to just allow users to set a
default saved search in Discover. There were some problems with that
approach though. It would change the default workflow in Discover.
Instead of starting with an unsaved search, users would be editing a
saved search by default. I could see this leading to a lot of
unintentional changes to the default. The settings from the default
saved search also wouldn't carry over to new searches, which I think
would be desirable most of the time.

I also considered adding a new advanced setting for specifying a default
sort field/direction. This kind of setting would make more sense at the
index pattern level though. One field may not be valid across all index
patterns.

So I ended up going with the simplest solution. It solves the issue
identified by the author of the linked issue and nothing more. If a sort
order is specified in the existing sort:options advanced setting, we'll
use that direction when sorting on the index pattern's timestamp field
by default.

Fixes #5164

* Create a new advanced setting instead of re-using sort:options

* Just pass a default order
  • Loading branch information
Bargs authored Aug 29, 2017
1 parent ecb10dc commit 43cca69
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ adapt to the interval between measurements. Keys are http://en.wikipedia.org/wik
document.
`discover:sampleSize`:: The number of rows to show in the Discover table.
`discover:aggs:terms:size`:: Determines how many terms will be visualized when clicking the "visualize" button, in the field drop downs, in the discover sidebar. The default value is `20`.
`discover:sort:defaultOrder`:: Controls the default sort direction for time based index patterns in the Discover app.
`doc_table:highlight`:: Highlight results in Discover and Saved Searches Dashboard. Highlighting makes request slow when
working on big documents. Set this property to `false` to disable highlighting.
`courier:maxSegmentCount`:: Kibana splits requests in the Discover app into segments to limit the size of requests sent to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function discoverController(
function getStateDefaults() {
return {
query: $scope.searchSource.get('query') || { query: '', language: config.get('search:queryLanguage') },
sort: getSort.array(savedSearch.sort, $scope.indexPattern),
sort: getSort.array(savedSearch.sort, $scope.indexPattern, config.get('discover:sort:defaultOrder')),
columns: savedSearch.columns.length > 0 ? savedSearch.columns : config.get('defaultColumns').slice(),
index: $scope.indexPattern.id,
interval: 'auto',
Expand Down
6 changes: 6 additions & 0 deletions src/core_plugins/kibana/ui_setting_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ export function getUiSettingDefaults() {
description: 'Determines how many terms will be visualized when clicking the "visualize" ' +
'button, in the field drop downs, in the discover sidebar.'
},
'discover:sort:defaultOrder': {
value: 'desc',
options: ['desc', 'asc'],
type: 'select',
description: 'Controls the default sort direction for time based index patterns in the Discover app.',
},
'doc_table:highlight': {
value: true,
description: 'Highlight results in Discover and Saved Searches Dashboard.' +
Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/doc_table/lib/get_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import _ from 'lodash';
* @param {object} indexPattern used for determining default sort
* @returns {object} a sort object suitable for returning to elasticsearch
*/
export function getSort(sort, indexPattern) {
export function getSort(sort, indexPattern, defaultSortOrder = 'desc') {
const sortObj = {};
let field;
let direction;
Expand All @@ -21,7 +21,7 @@ export function getSort(sort, indexPattern) {
direction = sort[1];
} else if (indexPattern.timeFieldName && isSortable(indexPattern.timeFieldName)) {
field = indexPattern.timeFieldName;
direction = 'desc';
direction = defaultSortOrder;
}

if (field) {
Expand All @@ -35,7 +35,7 @@ export function getSort(sort, indexPattern) {
return sortObj;
}

getSort.array = function (sort, indexPattern) {
return _(getSort(sort, indexPattern)).pairs().pop();
getSort.array = function (sort, indexPattern, defaultSortOrder) {
return _(getSort(sort, indexPattern, defaultSortOrder)).pairs().pop();
};

0 comments on commit 43cca69

Please sign in to comment.