New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent usage of ScriptScoreFunction in FiltersFunctionScoreQuery #3464
Labels
Comments
ghost
assigned brwe
Aug 8, 2013
@brwe cool! thanks for recording those commit IDs |
brwe
added a commit
to brwe/elasticsearch
that referenced
this issue
Aug 19, 2013
…Query This commit fixes inconsistencies in `function_score` and `filters_function_score` using scripts, see issue elastic#3464 The method 'ScoreFunction.factor(docId)' is removed completely, since the name suggests that this method actually computes a factor which was not the case. Multiplying the computed score is now handled by 'FiltersFunctionScoreQuery' and 'FunctionScoreQuery' and not implicitely performed in 'ScoreFunction.factor(docId, subQueryScore)' as was the case for 'BoostScoreFunction' and 'DecayScoreFunctions'. This commit also fixes the explain function for FiltersFunctionScoreQuery. Here, the influence of the maxBoost was never printed. Furthermore, the queryBoost was printed as beeing multiplied to the filter score. Closes elastic#3464
brwe
added a commit
that referenced
this issue
Aug 23, 2013
…Query This commit fixes inconsistencies in `function_score` and `filters_function_score` using scripts, see issue #3464 The method 'ScoreFunction.factor(docId)' is removed completely, since the name suggests that this method actually computes a factor which was not the case. Multiplying the computed score is now handled by 'FiltersFunctionScoreQuery' and 'FunctionScoreQuery' and not implicitely performed in 'ScoreFunction.factor(docId, subQueryScore)' as was the case for 'BoostScoreFunction' and 'DecayScoreFunctions'. This commit also fixes the explain function for FiltersFunctionScoreQuery. Here, the influence of the maxBoost was never printed. Furthermore, the queryBoost was printed as beeing multiplied to the filter score. Closes #3464
mute
pushed a commit
to mute/elasticsearch
that referenced
this issue
Jul 29, 2015
…Query This commit fixes inconsistencies in `function_score` and `filters_function_score` using scripts, see issue elastic#3464 The method 'ScoreFunction.factor(docId)' is removed completely, since the name suggests that this method actually computes a factor which was not the case. Multiplying the computed score is now handled by 'FiltersFunctionScoreQuery' and 'FunctionScoreQuery' and not implicitely performed in 'ScoreFunction.factor(docId, subQueryScore)' as was the case for 'BoostScoreFunction' and 'DecayScoreFunctions'. This commit also fixes the explain function for FiltersFunctionScoreQuery. Here, the influence of the maxBoost was never printed. Furthermore, the queryBoost was printed as beeing multiplied to the filter score. Closes elastic#3464
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scoring in
function_score
andfilters_function_score
queries is potentially inconsistent when using scripts.Brief overview of related classes
function_score
andfilters_function_score
allow a user to modify the score of a query (referred to as 'subQueryScore' from here on).In brief, there are two classes that compute scores based on a query and some function:
FunctionScoreQuery
, which only has one function andFiltersFunctionScoreQuery
which combines the result of several functions. For both classes, the function can be aScriptScoreFunction
.ScoreFunction
: Computes a score for a document. The two relevant methods are:score(docId, subQueryScore)
: computes a new score taking into account thesubQueryScore
and some other properties of a documents.factor(docId)
: computes a score solely based on properties of the document.FunctionScoreQuery.score()
computes:score =
subQueryBoost
*ScoreFunction.score(docId, subQueryScore)
FiltersFunctionScoreQuery.CustomBoostFactorScorer.score()
computes:score =
subQueryScore
*subQueryBoost
*combine(ScoreFunction1.factor(docId), ScoreFunction2.factor(docId),…)
where combine can mean add, multiply, lowest value, etc.
The problem
ScoreFunctions.factor(docId)
implies that the method computes a factor only and does not take into account thesubQueryScore
. This is the way theScoreFunctions
are used inFiltersFunctionScoreQuery.CustomBoostFactorScorer
: The methodfactor()
is called for each score function and the result is than later multiplied to thesubQueryScore
.However, the
ScriptScoreFunction
violates this principle: scripts can use the_score
variable which should be initialized with thesubQueryScore
before the script is run, seeScriptScoreFunction.score(..)
. IfScriptScoreFunction.factor()
is called, then the behavior is undefined, since the_score
variable is either wrong or maybe even not initialized.This might cause unexpected behavior since this inconsistency is not transparent to the user.
The text was updated successfully, but these errors were encountered: