0
0
Elasticsearchquery~5 mins

Function score query in Elasticsearch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a function score query in Elasticsearch?
A function score query lets you modify the score of documents returned by a query using functions like boosting, decay, or script scoring. It helps customize how results are ranked.
Click to reveal answer
beginner
Name two common functions used inside a function score query.
Common functions include weight (to boost scores by a fixed number) and decay functions like gauss or exp that reduce scores based on distance from a point.
Click to reveal answer
intermediate
What does the boost_mode parameter do in a function score query?
boost_mode controls how the original query score and the function score combine. Options include multiply, sum, replace, and more.
Click to reveal answer
intermediate
Explain the purpose of the score_mode in a function score query.
score_mode defines how multiple functions' scores combine when more than one function applies. For example, sum adds them, multiply multiplies them, and max picks the highest.
Click to reveal answer
beginner
Show a simple example of a function score query that boosts documents with a field is_featured set to true.
Example:
{
  "query": {
    "function_score": {
      "query": { "match_all": {} },
      "functions": [
        {
          "filter": { "term": { "is_featured": true } },
          "weight": 5
        }
      ],
      "boost_mode": "multiply"
    }
  }
}
Click to reveal answer
What does a function score query primarily do in Elasticsearch?
AModify the score of documents returned by a query
BChange the index mapping
CDelete documents from the index
DCreate a new index
Which parameter controls how the original score and function score combine?
Ascore_mode
Bquery_mode
Cfilter_mode
Dboost_mode
If you want to add scores from multiple functions, which score_mode should you use?
Asum
Bmultiply
Cmax
Dreplace
Which function would you use to boost documents with a specific field value?
Agauss
Bscript_score
Cweight
Drandom_score
What is the effect of setting boost_mode to replace?
AOriginal score is multiplied by function score
BFunction score replaces the original score
CScores are added together
DScores are averaged
Describe what a function score query is and why you might use it.
Think about how you can change the importance of search results.
You got /4 concepts.
    Explain the difference between boost_mode and score_mode in a function score query.
    One controls original vs function, the other controls multiple functions.
    You got /3 concepts.