Skip to content

[5.x] Fix sorting on scripted date and boolean fields#9286

Merged
epixa merged 1 commit into5.xfrom
jasper/backport/9261/5.x
Nov 30, 2016
Merged

[5.x] Fix sorting on scripted date and boolean fields#9286
epixa merged 1 commit into5.xfrom
jasper/backport/9261/5.x

Conversation

@elastic-jasper
Copy link
Contributor

Fix sorting on scripted date and boolean fields

Backports PR #9261

Commit 1:
Fix sorting on scripted date and boolean fields

The elasticsearch API only supports2 sort scripts of type number and
string. Since dates need to be returned as millis since the epoch for
visualizations to work anyway, we can simply add a condition to send dates
as type number in the sort API. ES will cast booleans if we tell them
its a string, so we can add a similar condition there as well.

Fixes: #9257

Commit 2:
Add helpful comment

Backports PR #9261

**Commit 1:**
Fix sorting on scripted date and boolean fields

The elasticsearch API only [supports][1][2] sort scripts of type `number` and
`string`. Since dates need to be returned as millis since the epoch for
visualizations to work anyway, we can simply add a condition to send dates
as type number in the sort API. ES will cast booleans if we tell them
its a string, so we can add a similar condition there as well.

[1]: https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-sort.html#_script_based_sorting
[2]: https://github.com/elastic/elasticsearch/blob/aeb97ff41298e26b107a733837dfe17f123c0c9b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java#L359

Fixes: #9257

* Original sha: 0d5a824
* Authored by Matthew Bargar <mbargar@gmail.com> on 2016-11-29T21:05:48Z

**Commit 2:**
Add helpful comment

* Original sha: 14dc396
* Authored by Matthew Bargar <mbargar@gmail.com> on 2016-11-30T21:02:41Z
@elastic-jasper elastic-jasper added the backport This PR is a backport of another PR label Nov 30, 2016
@epixa epixa merged commit 851ba23 into 5.x Nov 30, 2016
@epixa epixa deleted the jasper/backport/9261/5.x branch November 30, 2016 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments