Sorting by Likes and Dislikes

I've been struggling to express the current logic problem I'm trying to solve with Elasticsearch, and I think I have a good way to represent it.

Let's say I'm building out an API to sort Mario Kart characters in order of the user's preference. The user can list characters they like, and those they dislike. Here is the data set:

{character: {name: "Mario", weight: "Light"}},
{character: {name: "Luigi", weight: "Medium"}},
{character: {name: "Peach", weight: "Light"}},
{character: {name: "Bowser", weight: "Heavy"}},
{character: {name: "Toad", weight: "Light"}},
{character: {name: "Koopa", weight: "Medium"}}

The user inputs that they like Mario and Luigi and do not like Bowser. With Elasticsearch, how could I go about sorting this data for the user so the list is returned like so:

[Mario (+), Luigi (+), Peach, Toad, Koopa, Bowser (-)]

*Pluses and minuses in there for legibility.

This would return the user's top choices in front, the ones they are OK with in the middle, and the ones they don't prefer at the end. Having to use nested queries really trips me up here.

Evolving the query, let's say there's a team mode where each team is comprised of pairs of two, determined by the game in the following pairs:

[Luigi (+), Bowser (-)]
[Mario (+), Peach]
[Toad, Koopa]

How to I ensure that I don't filter out teams that contain Bowser, yet still weight the results so that it's like so:

[Mario (+), Peach]
[Toad, Koopa]
[Luigi (+), Bowser (-)]

Or, should [Luigi, Bowser] actually rank second?

I'm very confused about building complex queries like these in Elasticsearch and would appreciate any help.

I'm not sure if this going to help but I'm feeling that the answer is in the way you can compute score here and not sort. Which kind of similar because by default elasticsearch sort on score.

How to adapt the score to your needs? I'd look at Function Score Query where you can put some specific weight to anything that match for example Light (let say score=3), Medium (score=2) and Heavy (score=1).

I hope this could give you some ideas...

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.