mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
move scripted sorting into normalize_sort_request
This commit is contained in:
parent
b4c4d7ee20
commit
954e6d40f3
2 changed files with 20 additions and 6 deletions
|
@ -6,7 +6,7 @@ define(function (require) {
|
|||
* @param {query} query object
|
||||
* @returns {object}
|
||||
*/
|
||||
return function (sortObject) {
|
||||
return function (sortObject, indexPattern) {
|
||||
if (!_.isArray(sortObject)) sortObject = [sortObject];
|
||||
var defaultSortOptions = config.get('sort:options');
|
||||
|
||||
|
@ -17,11 +17,26 @@ define(function (require) {
|
|||
_.each(sortObject, function (sortable) {
|
||||
var sortField = _.keys(sortable)[0];
|
||||
var sortValue = sortable[sortField];
|
||||
if (_.isString(sortValue)) {
|
||||
sortValue = sortable[sortField] = { order: sortValue };
|
||||
var indexField = indexPattern.fields.byName[sortField];
|
||||
|
||||
if (indexField && indexField.scripted && indexField.sortable) {
|
||||
var direction = sortValue;
|
||||
delete(sortable[sortField]);
|
||||
sortField = '_script';
|
||||
|
||||
sortValue = sortable[sortField] = {
|
||||
script: indexField.script,
|
||||
type: indexField.type,
|
||||
order: direction
|
||||
};
|
||||
} else {
|
||||
if (_.isString(sortValue)) {
|
||||
sortValue = sortable[sortField] = { order: sortValue };
|
||||
}
|
||||
_.defaults(sortValue, defaultSortOptions);
|
||||
}
|
||||
_.defaults(sortValue, defaultSortOptions);
|
||||
});
|
||||
|
||||
return sortObject;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -8,7 +8,6 @@ define(function (require) {
|
|||
var SegmentedRequest = Private(require('components/courier/fetch/request/segmented'));
|
||||
var normalizeSortRequest = Private(require('components/courier/data_source/_normalize_sort_request'));
|
||||
|
||||
|
||||
_(SearchSource).inherits(SourceAbstract);
|
||||
function SearchSource(initialState) {
|
||||
SearchSource.Super.call(this, initialState);
|
||||
|
@ -179,7 +178,7 @@ define(function (require) {
|
|||
key = '_source';
|
||||
/* fall through */
|
||||
case 'sort':
|
||||
val = normalizeSortRequest(val);
|
||||
val = normalizeSortRequest(val, this.get('index'));
|
||||
/* fall through */
|
||||
default:
|
||||
state.body = state.body || {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue