From b5cb6ef4befe65c40ae9cacae2243ec44a4f63cc Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Fri, 25 Aug 2017 12:19:42 -0400 Subject: [PATCH 1/3] 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 --- .../kibana/public/discover/controllers/discover.js | 2 +- src/ui/public/doc_table/lib/get_sort.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core_plugins/kibana/public/discover/controllers/discover.js b/src/core_plugins/kibana/public/discover/controllers/discover.js index b475c24855a41..e8de30680d3ce 100644 --- a/src/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/core_plugins/kibana/public/discover/controllers/discover.js @@ -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('sort:options')), columns: savedSearch.columns.length > 0 ? savedSearch.columns : config.get('defaultColumns').slice(), index: $scope.indexPattern.id, interval: 'auto', diff --git a/src/ui/public/doc_table/lib/get_sort.js b/src/ui/public/doc_table/lib/get_sort.js index 9d881abeba195..c4a4de57d3392 100644 --- a/src/ui/public/doc_table/lib/get_sort.js +++ b/src/ui/public/doc_table/lib/get_sort.js @@ -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, sortOptions = {}) { 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 = sortOptions.order || 'desc'; } 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, sortOptions) { + return _(getSort(sort, indexPattern, sortOptions)).pairs().pop(); }; From 2b7c73e9f6d13443503b0f21a122d69b4d9613ac Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Mon, 28 Aug 2017 17:33:16 -0400 Subject: [PATCH 2/3] Create a new advanced setting instead of re-using sort:options --- docs/management/advanced-options.asciidoc | 1 + .../kibana/public/discover/controllers/discover.js | 2 +- src/core_plugins/kibana/ui_setting_defaults.js | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/management/advanced-options.asciidoc b/docs/management/advanced-options.asciidoc index 43350d03e15e7..3f9f8319fc4cb 100644 --- a/docs/management/advanced-options.asciidoc +++ b/docs/management/advanced-options.asciidoc @@ -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 diff --git a/src/core_plugins/kibana/public/discover/controllers/discover.js b/src/core_plugins/kibana/public/discover/controllers/discover.js index e8de30680d3ce..90286f92a0de6 100644 --- a/src/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/core_plugins/kibana/public/discover/controllers/discover.js @@ -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, config.get('sort:options')), + sort: getSort.array(savedSearch.sort, $scope.indexPattern, { order: config.get('discover:sort:defaultOrder') }), columns: savedSearch.columns.length > 0 ? savedSearch.columns : config.get('defaultColumns').slice(), index: $scope.indexPattern.id, interval: 'auto', diff --git a/src/core_plugins/kibana/ui_setting_defaults.js b/src/core_plugins/kibana/ui_setting_defaults.js index 36a8b7f26e6d4..b798aaf101005 100644 --- a/src/core_plugins/kibana/ui_setting_defaults.js +++ b/src/core_plugins/kibana/ui_setting_defaults.js @@ -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.' + From faba375bd9789e5e40c5be031d7491bee332d04a Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Tue, 29 Aug 2017 11:09:00 -0400 Subject: [PATCH 3/3] Just pass a default order --- .../kibana/public/discover/controllers/discover.js | 2 +- src/ui/public/doc_table/lib/get_sort.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core_plugins/kibana/public/discover/controllers/discover.js b/src/core_plugins/kibana/public/discover/controllers/discover.js index 90286f92a0de6..5d6a3237e8fc0 100644 --- a/src/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/core_plugins/kibana/public/discover/controllers/discover.js @@ -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, { order: config.get('discover:sort:defaultOrder') }), + 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', diff --git a/src/ui/public/doc_table/lib/get_sort.js b/src/ui/public/doc_table/lib/get_sort.js index c4a4de57d3392..e4749d8439131 100644 --- a/src/ui/public/doc_table/lib/get_sort.js +++ b/src/ui/public/doc_table/lib/get_sort.js @@ -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, sortOptions = {}) { +export function getSort(sort, indexPattern, defaultSortOrder = 'desc') { const sortObj = {}; let field; let direction; @@ -21,7 +21,7 @@ export function getSort(sort, indexPattern, sortOptions = {}) { direction = sort[1]; } else if (indexPattern.timeFieldName && isSortable(indexPattern.timeFieldName)) { field = indexPattern.timeFieldName; - direction = sortOptions.order || 'desc'; + direction = defaultSortOrder; } if (field) { @@ -35,7 +35,7 @@ export function getSort(sort, indexPattern, sortOptions = {}) { return sortObj; } -getSort.array = function (sort, indexPattern, sortOptions) { - return _(getSort(sort, indexPattern, sortOptions)).pairs().pop(); +getSort.array = function (sort, indexPattern, defaultSortOrder) { + return _(getSort(sort, indexPattern, defaultSortOrder)).pairs().pop(); };