Challenge - 5 Problems
Function Score Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this function score query?
Given the following Elasticsearch function score query, what is the resulting score for a document with
field1 value 5 and field2 value 10?Elasticsearch
{
"query": {
"function_score": {
"query": { "match_all": {} },
"functions": [
{
"field_value_factor": {
"field": "field1",
"factor": 2,
"modifier": "sqrt"
}
},
{
"field_value_factor": {
"field": "field2",
"factor": 1.5
}
}
],
"score_mode": "sum",
"boost_mode": "replace"
}
}
}Attempts:
2 left
💡 Hint
Remember that the score_mode 'sum' adds the results of each function, and boost_mode 'replace' uses the function score as the final score.
✗ Incorrect
The first function applies sqrt modifier to field1 (sqrt(5) ≈ 2.236) multiplied by factor 2 → 4.472. The second function multiplies field2 by 1.5 → 15. Sum is 4.472 + 15 = 19.472.
🧠 Conceptual
intermediate1:00remaining
Which score_mode combines function scores by multiplying them?
In an Elasticsearch function score query, which
score_mode option multiplies the scores from each function together?Attempts:
2 left
💡 Hint
Think about how scores combine when you want to increase or decrease the total score multiplicatively.
✗ Incorrect
The
score_mode "multiply" multiplies the scores from each function to produce the final score.🔧 Debug
advanced1:30remaining
Why does this function score query cause a syntax error?
Identify the syntax error in this function score query snippet:
Elasticsearch
{
"query": {
"function_score": {
"query": { "match_all": {} },
"functions": [
{
"field_value_factor": {
"field": "popularity",
"factor": 1.2
}
},
{
"random_score": {
"seed": 12345
}
}
],
"score_mode": "sum",
"boost_mode": "multiply"
}
}
}Attempts:
2 left
💡 Hint
Check if all braces and brackets are properly closed.
✗ Incorrect
The JSON is missing the closing brace '}' at the end, causing a syntax error.
📝 Syntax
advanced1:30remaining
Which option correctly uses a filter in a function score query?
Select the option that correctly applies a filter to a function inside a function score query.
Attempts:
2 left
💡 Hint
The filter must be a sibling of weight inside the function object.
✗ Incorrect
The correct syntax places 'weight' first and 'filter' as a sibling key with a valid term query. Option A is valid.
🚀 Application
expert2:00remaining
How many functions are applied in this function score query?
Given this function score query, how many scoring functions are applied?
Elasticsearch
{
"query": {
"function_score": {
"query": { "match": { "title": "search" } },
"functions": [
{ "weight": 3 },
{ "field_value_factor": { "field": "popularity", "factor": 1.1 } },
{ "random_score": {} },
{ "script_score": { "script": "doc['views'].value / 10" } }
],
"score_mode": "avg",
"boost_mode": "multiply"
}
}
}Attempts:
2 left
💡 Hint
Count each object inside the 'functions' array.
✗ Incorrect
There are 4 function objects inside the 'functions' array: weight, field_value_factor, random_score, and script_score.