Reputation: 16281
I have added a sort
conditions field to my ElasticSearch query. I'm using ES 7.14 / Kibana 7.10, with a "fallback" to the document's score. According to the docs I have to use the reserved key _score
:
My sort
array field look like
[
{ "update_date": { "order": "desc", "missing" : "_last", "unmapped_type" : "long" } },
{ "release_date": { "order": "desc", "missing" : "_last", "unmapped_type" : "long" } },
"_score"
]
This works ok, but I get a null
value for score
when not using the _score
special field. Why? Is the score
not calculated when using the sort
conditions at all?
Upvotes: 1
Views: 1810
Reputation: 5486
Yes, your understanding is correct that sort will not calculate when sorting applied to another field. ES Documentation is quoted below for same:
When sorting on a field, scores are not computed. By setting track_scores to true, scores will still be computed and tracked.
So If you want to calculate score then you can enable by providing "track_scores": true parameter.
{
"track_scores": true,
"sort" : [
{ "post_date" : {"order" : "desc"} },
{ "name" : "desc" },
{ "age" : "desc" }
],
"query" : {
"term" : { "user" : "kimchy" }
}
}
Upvotes: 4