Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sorting on scripted date and boolean fields #9261

Merged
merged 2 commits into from
Nov 30, 2016
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
Contributor

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