title: Elasticsearch Sorting by Likes and Dislikes
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>{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"}}
  </code></pre>
  
  <p>The user inputs that they like <code>Mario</code> and <code>Luigi</code> and do not like <code>Bowser</code>. With Elasticsearch, how could I go about sorting this data for the user so the list is returned like so:</p>
  
  <pre><code>[Mario (+), Luigi (+), Peach, Toad, Koopa, Bowser (-)]
  </code></pre>
  
  <p>*Pluses and minuses in there for legibility.</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>[Luigi (+), Bowser (-)]
  [Mario (+), Peach]
  [Toad, Koopa]
  </code></pre>
  
  <p>How to I ensure that I don't filter out teams that contain <code>Bowser</code>, yet still weight the results so that it's like so:</p>
  
  <pre><code>[Mario (+), Peach]
  [Toad, Koopa]
  [Luigi (+), Bowser (-)]
  </code></pre>
  
  <p>Or, should <code>[Luigi, Bowser]</code> actually rank second?</p>
  
  <p>I'm very confused about building complex queries like these in Elasticsearch and would appreciate any help.</p>