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]
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.
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
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.