13

The documentation says that using a field_value_factor value of:

"field_value_factor": {
  "field": "popularity",
  "factor": 1.2,
  "modifier": "sqrt",
  "missing": 1
}

"Which will translate into the following formula for scoring:

sqrt(1.2 * doc['popularity'].value) "

But what I do not understand is what is done with sqrt(1.2 * doc['popularity'].value) ? Is it multiplied by the original score of each hit to create a new score? Is it added? Can I change whether it is multiplied or added?

Is that what is defined in function_score["boost_mode"]?

user3494047
  • 1,643
  • 4
  • 31
  • 61

1 Answers1

27

yeah you are in the right direction. Two properties control the overall combination of individual scores and the score for the function score and naturally evaluated score. They are

  • score_mode - This variable control how the computed scores are combined:

  • boost_mode - This variable control how query score and computed score are combined

Reference

Take a look at the following query

{
    "query": {
        "function_score": {
            "query": {
                "match_all": {}
            },
            "functions": [{
                "field_value_factor": {
                    "field": "popularity",
                    "factor": 1.2,
                    "modifier": "sqrt",
                    "missing": 1
                }
            }, {
                "linear": {
                    "distance": {
                        "origin": "0",
                        "scale": "0.4"
                    }
                }
            }, {
                "gauss": {
                    "price": {
                        "origin": "0",
                        "scale": ".08"
                    }
                }
            }],
            "score_mode": "multiply",
            "boost_mode": "sum"
        }
    }
}

Since score_mode is multiply, as you can see there are three functions in my function score query, so this will multiply the score of each fucntion

function_score = score_linear * score_gauss * score_field_value_factor

Again - boost_mode is sum, so my final score will the summations of overall score evaluated by function score and the query score.

document_score = function_score + query_score.

Thanks

user3775217
  • 4,675
  • 1
  • 22
  • 33