Confused on how to do should and should not + boosting

I'm writing an API that utilizes facets to suggest products to end users based on their settings. The data is multi-faceted in the sense that a user can combine filters from multiple categories. What's more, the returned result should not be limited to exact results, but return a list of X items based on query score.

The data is proprietary, so I switched out the mapping to replace the real fields with Nintendo-based examples so we can all have a good time while I get some much needed Elasticsearch help.

Example: A user is looking for games where Mario and Luigi should be playable, but Bowser should not. The game should be for SNES and should not be for NES:

{
  "query": {
	"bool": {
	  "should": [
		{
			"nested": {
			"score_mode" : "sum",
			"path": "players",
			"query": { "bool": {"must": [
			  { "terms": { "players.name": ["Mario", "Luigi"] } }
			]}}
		  }
		},
		{
			"nested": {
			"score_mode" : "sum",
			"path": "console",
			"query": {"bool": {"must": [
			  { "terms": { "console.name": ["SNES"] } }
			]}}
		  }
		},
		{
		  "nested": {
			"score_mode" : "min",
			"path": "players",
			"query": {"bool": {"must_not": [
			  { "terms": { "players.name": ["Bowser"] } }
			]}}
		  }
		},
		{
		  "nested": {
			"score_mode" : "min",
			"path": "console",
			"query": {"bool": {"must_not": [
			  { "terms": { "console.name": ["NES"] } }
			]}}
		  }
		}
	  ]
	}
  }
}

Results:

"hits": [
	  {
		"_index": "games",
		"_type": "game",
		"_id": "4aee02d4-6b83-11e8-8938-294f2d4dc7ef",
		"_score": 5,
		"_source": {
		  "console": [
			{
			  "name": "SNES"
			}
		  ],
		  "players": [
			{
			  "name": "Luigi"
			},
			{
			  "name": "Mario"
			}
		  ]
		}
	  },
	  {
		"_index": "games",
		"_type": "game",
		"_id": "4795963e-6b88-11e8-a4cb-732f847dc805",
		"_score": 5,
		"_source": {
		  "console": [
			{
			  "name": "NES"
			},
			{
			  "name": "SNES"
			}
		  ],
		  "players": [
			{
			  "name": "Mario"
			},
			{
			  "name": "Luigi"
			},
			{
			  "name": "Peach"
			},
			{
			  "name": "Toad"
			}
		  ]
		}
	  },
	  {
		"_index": "games",
		"_type": "game",
		"_id": "800569c5-6b89-11e8-b27b-f7dae11d9bc9",
		"_score": 4,
		"_source": {
		  "console": [
			{
			  "name": "SNES"
			}
		  ],
		  "players": [
			{
			  "name": "Mario"
			}
			{
			  "name": "Bowser"
			}
		  ]
		}
	  },
	  {
		"_index": "games",
		"_type": "game",
		"_id": "13325f86-6b89-11e8-bfea-1fe5e2b5a461",
		"_score": 4,
		"_source": {
		  "console": [
			{
			  "name": "SNES"
			},
			{
			  "name": "NES"
			}
		  ],
		  "players": [
			{
			  "name": "Mario"
			},
			{
			  "name": "Bowser"
			}
		  ]
		}
	  },
	  {
		"_index": "games",
		"_type": "game",
		"_id": "256d4dcb-6b86-11e8-b4e0-3fece057ccb0",
		"_score": 3,
		"_source": {
		  "console": [
			{
			  "name": "SNES"
			}
		  ],
		  "players": [
			{
			  "name": "Mega Man"
			}
		  ]
		}
	  },
	  {
		"_index": "games",
		"_type": "game",
		"_id": "5bcda1fa-6b87-11e8-a411-e7f5fa3abcdd",
		"_score": 3,
		"_source": {
		  "console": [
			{
			  "name": "SNES"
			},
			{
			  "name": "NES"
			}
		  ],
		  "players": [
			{
			  "name": "Fox McCloud"
			}
		  ]
		}
	  },
	  {
		"_index": "games",
		"_type": "game",
		"_id": "e3020f5c-6b87-11e8-8cc6-87fc791a9c1a",
		"_score": 2,
		"_source": {
		  "console": [
			{
			  "name": "NES"
			}
		  ],
		  "players": [
			{
			  "name": "Kid Icarus"
			}
		  ]
		}
	  },
	  {
		"_index": "games",
		"_type": "game",
		"_id": "48291645-6b83-11e8-a4cb-732f847dc805",
		"_score": 2,
		"_source": {
		  "console": [
			{
			  "name": "N64"
			}
		  ],
		  "players": [
			{
			  "name": "James Bond"
			}
		  ]
		}
	  }
	]

I'm awfully confused about how the scoring works. I've played around with the scoring types as seen in my ES query, but not sure how to make it so that negative hits are ranked lower. For instance, why would a game that matches 2 negatives and 2 positives give a score of 4, in the case of game 13325f86-6b89-11e8-bfea-1fe5e2b5a461?

Then, if I wanted to boost a category, for instance console, I can't figure out how to do it with terms.

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