Reorder results to ensure the closest match returns first

I'd like to make a single rescore query that pushes the closest metadata match to what someone searched (before applying the function score), but then have the function score as a much larger factor afterwards, in order to bring in other factors (such as user behaviour and recency), whilst still optimising for people searching for a specific document.

In essence, I'd like to run a rescore query of window-size, 100, but that runs from position 2 onwards and leaves the first position as is. I couldn't seem to find any way to do this, so instead I looked at doing a rescore query that only boosts a single document, but ran into "size:" not being supported in rescore query (I assume because the rescore is trying to rescore all the documents in its window).

I was then hoping to run a function/script score inside the rescore query so that the boost from the first document would be much larger than for all the other documents. However, I then ran into the issue of not being able to access the max_score for the query without running a separate query first and then using that max_score to bomb out all the other results. I'd rather keep everything inside one query if at all possible so as not to double our traffic.

Is there any way to do this within a single query, or is that beyond the scope of basic queries without getting into something like learn-to-rank?

tl;dr - optimise first result for highest elastic query score, then after that bring in a function score

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