In case this helps someone, here's how I recently implemented a weighted shuffle.
In this example, we are shuffling companies. Each company has a "company_score" from 0 to 100. With this simple weighted shuffle, a company with a score of 100 appears 5 times more often on the first page than a company with a score of 20.
json_body = { "sort": ["_score"], "query": { "function_score": { "query": main_query, # put your main query here "functions": [ { "random_score": {}, }, { "field_value_factor": { "field": "company_score", "modifier": "none", "missing": 0, } } ], # How to combine the result of the two functions 'random_score' and 'field_value_factor'. # This way, on average the combined _score of a company having score 100 will be 5 times as much # as the combined _score of a company having score 20, and thus will be 5 times more likely # to appear on first page. "score_mode": "multiply", # How to combine the result of function_score with the original _score from the query. # We overwrite it as our combined _score (random x company_score) is all we need. "boost_mode": "replace", } } }
Vermeer grange
source share