diff --git a/src/ui/public/courier/data_source/_normalize_sort_request.js b/src/ui/public/courier/data_source/_normalize_sort_request.js index 7bab633bf1d4c..beb9f3f6effa8 100644 --- a/src/ui/public/courier/data_source/_normalize_sort_request.js +++ b/src/ui/public/courier/data_source/_normalize_sort_request.js @@ -38,7 +38,7 @@ export default function normalizeSortRequest(config) { inline: indexField.script, lang: indexField.lang }, - type: indexField.type, + type: castSortType(indexField.type), order: direction }; } else { @@ -56,3 +56,20 @@ export default function normalizeSortRequest(config) { return normalized; } }; + +// The ES API only supports sort scripts of type 'number' and 'string' +function castSortType(type) { + const typeCastings = { + number: 'number', + string: 'string', + date: 'number', + boolean: 'string' + }; + + const castedType = typeCastings[type]; + if (!castedType) { + throw new Error(`Unsupported script sort type: ${type}`); + } + + return castedType; +}