3

I'm using Amazon's AWS CloudSearch service, and I'm trying to figure out the sort function. I know how to sort by _score, text fields alphabetically, and a combination of _score and int fields, but I want to sort by _score and a text field.

I have an index on title of type text. Here is some sample data:

Win the War
A War is Coming
Just a Battle
War of the Wars
Come to the War

If I do a search for war, I want the following results (simplified score).

How do I sort by (_score desc, title asc) - score descending followed by title ascending for the results with the same score?

Score |  Title
------+-------------------
   2  |  War of the Wars
   1  |  A War is Coming
   1  |  Come to the War
   1  |  Win the War

I'm using the Java AWS SDK, so hopefully it's doable with that.

Matt
  • 828
  • 8
  • 25
  • I've implemented a solution in Java by returning `_all_fields,_score` and using a custom `Comparator` to sort by score then title. I'd really like to know if there's a way to do it purely with the API. – Matt Dec 14 '17 at 15:21
  • It's been a while but I am pretty sure you can do this with a custom ranker expression http://docs.aws.amazon.com/cloudsearch/latest/developerguide/defining-expressions-in-requests.html – alexroussos Dec 19 '17 at 15:10
  • As far as I can tell, the way you've figured out is the only solution. I thought expressions might help, but you cannot use a text field in a search expression. – dmbaughman Jan 04 '18 at 21:12

0 Answers0