Prevent field_value_factor from calculating negative scores #41509
Description
Not 100% sure this is a bug report (or whether it should be a change request).
This issue is related to #33309 and #35709
Elasticsearch version (bin/elasticsearch --version
):
Version: 7.0.0, Build: default/tar/b7e28a7/2019-04-05T22:55:32.697037Z, JVM: 1.8.0_152
Plugins installed:
- analysis-icu 7.0.0
- analysis-kuromoji 7.0.0
- analysis-phonetic 7.0.0
JVM version (java -version
):
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
OS version (uname -a
if on a Unix-like system):
Darwin Daniels-MacBook-Pro-Elastic.local 17.7.0 Darwin Kernel Version 17.7.0: Wed Feb 27 00:43:23 PST 2019; root:xnu-4570.71.35~1/RELEASE_X86_64 x86_64
Description of the problem including expected versus actual behavior:
Using the "wrong" modifier in a field_value_factor currently can result in a negative factor which would result in a negative score which again gets prevented by raising exception field value function must not produce negative scores
. As a consequence, such a query won't return any results.
Wouldn't it be more reasonable to prevent field_value_factor from returning negative values by returning 0 (=max(0, modified score)) in cases like the modifier function computing a negative value (example ln(0.8)
)?
Or as an alternative, no longer support now potentially "dangerous" modifier functions such as ln
?
Steps to reproduce:
Please include a minimal but complete recreation of the problem, including
(e.g.) index creation, mappings, settings, query etc. The easier you make for
us to reproduce it, the more likely that somebody will take the time to look at it.
Step 1
POST test/_doc/1
{
"title": "Test document",
"popularity": 0.8
}
Step 2
GET test/_search
{
"query": {
"function_score": {
"query": {
"match": {
"title": "test"
}
},
"functions": [
{
"field_value_factor": {
"field": "popularity",
"missing": 1,
"modifier": "ln"
}
}
],
"boost_mode": "sum"
}
}
Provide logs (if relevant):