0

How can I do a sort with elastic search where the results would be sorted by the score AND another criteria, like an int.

Currently I can add multiple sort criteria, but I want the score to be one of them and I want to group scores in clusters of values (the width of the cluster being one parameter); then apply the second sort criteria to each bucket

For example, I have 5 hits:

A Score=1.0 Int=3
B Score=0.8 Int=2
C Score=0.8 Int=4
D Score=0.7 Int=5
E Score=0.84 Int=3

I would like this sorted like that:

Bucket 1 - Score 1.xxxxx
    A Score=1.0 Int=3

Bucket 2 - Score 0.8xxxxx
    C Score=0.8 Int=4
    E Score=0.84 Int=3
    B Score=0.8 Int=2

Bucket 3 - Score 0.7xxxxx
    D Score=0.7 Int=5

This means that the data is grouped by Score buckets and each bucket sorted by Int.

Thomas
  • 10,933
  • 14
  • 65
  • 136
  • You can refer to the calculated score by using the field `_score` – Russ Cam Jul 03 '16 at 21:52
  • If I do a sort by score, then by int, the example above would return A E C B D instead of A C E B D – Thomas Jul 03 '16 at 23:58
  • That's correct; if scores are tied then the one with the highest int will be ordered first. What you're essentially wanting to do is _rescore_ documents, giving them a score based on the first significant figure of their original score, then sort on `_score` then `Int` descending. That will achieve what you want. Take a look at rescoring - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-rescore.html – Russ Cam Jul 04 '16 at 00:19
  • Exactly what I needed, thanks! – Thomas Jul 04 '16 at 13:13

0 Answers0