Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/ui/public/courier/data_source/_normalize_sort_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}