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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add a comment, something like what is in the issue, The elasticsearch API only supports sort scripts of type number and string, so cast ..... Then maybe some day down the line if es API changes and does support sort of those types, we'll know it's safe to remove this extra code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added! Thanks for the review

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;
}