Preserving _score when using function_score with boost_mode="replace"

(Robert Voyer) #1

Hi folks,

I am successfully using function_score to customize result scoring. Presently, I am setting boost_mode="replace". But I'm wondering if it's possible to preserve the internal ES _score field in someway before doing that replacement. I thought I could achieve this by adding a script_field script that simply returns _score, but it seems as though I cannot reference _score from a script_field script:

ExpressionScriptCompilationException[Unknown variable [_score] in expression]

Is there another way to achieve this?

Thanks for your help!


(Robert Voyer) #2

Hi folks,

Here's some additional context around this... We are combining the internal _score with a few other scores produced with function_score scripts. We are adding all of those scores together (hence the use of boost_mode="replace"). For debugging purposes, as well as learning a more optimal way to combine each of the function_score outputs, we would like to (optionally) return each of the values used as the basis of scoring. So I am wondering if there's a way to copy the _score field to another field before replacing the internal score with the output of the function_score computation.

Any insight is greatly appreciated.


(Doug Turnbull) #3

I don't think that's currently possible. Related, by colleague wanted to multiply the scores of two queries, here's the best we got as an answer. At the risk of being tarred and feathered, Solr's function queries currently allow more flexibility in this area (as shown in that stackoverflow answer). Solr's function queries though can be a royal pain to work with compared to writing an honest-to-goodness script that ES gives you.

Sorry that's not a real answer, but hopefully someone will chime in because I would also like to do more with function_score_queries :smile:

(Robert Voyer) #4

Thanks for your response, Doug. Sounds like it might be worth digging into the ES source to see if I can contribute this myself.

(system) #5