Check sort:options for Discover default sort order (#13708) (#13763)

* 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 https://github.com/elastic/kibana/issues/5164

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

* Just pass a default order
This commit is contained in:
Matt Bargar 2017-08-29 17:07:12 -04:00 committed by GitHub
parent 14cb571179
commit b942987fed
4 changed files with 12 additions and 5 deletions

View file

@ -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

View file

@ -253,7 +253,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',

View file

@ -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.' +

View file

@ -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;
@ -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) {
@ -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();
};