0
0
Elasticsearchquery~10 mins

Function score query in Elasticsearch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a function score query with the correct key.

Elasticsearch
{
  "[1]": {
    "query": {
      "match_all": {}
    }
  }
}
Drag options to blanks, or click blank then click option'
Afunction_score
Bmatch
Cbool
Dterm
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'match' or 'bool' instead of 'function_score' as the root key.
2fill in blank
medium

Complete the code to add a weight function inside the function score query.

Elasticsearch
{
  "function_score": {
    "query": { "match_all": {} },
    "functions": [
      {
        "[1]": 5
      }
    ]
  }
}
Drag options to blanks, or click blank then click option'
Arandom_score
Bscript_score
Cweight
Dfield_value_factor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'script_score' or 'random_score' when a fixed weight is needed.
3fill in blank
hard

Fix the error in the function score query by completing the missing key for the filter.

Elasticsearch
{
  "function_score": {
    "query": { "match_all": {} },
    "functions": [
      {
        "filter": { "term": { "status": "active" } },
        "weight": 3
      }
    ],
    "[1]": "sum"
  }
}
Drag options to blanks, or click blank then click option'
Amax_boost
Bscore_mode
Cboost_mode
Dmin_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'boost_mode' or 'min_score' instead of 'score_mode' for combining function scores.
4fill in blank
hard

Fill both blanks to create a function score query that uses a field value factor and multiplies the score.

Elasticsearch
{
  "function_score": {
    "query": { "match": { "title": "[1]" } },
    "functions": [
      {
        "field_value_factor": {
          "field": "popularity"
        }
      }
    ],
    "[2]": "multiply"
  }
}
Drag options to blanks, or click blank then click option'
Aelasticsearch
Bscore_mode
Cboost_mode
Dquery_string
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query_string' instead of the search term.
Confusing 'boost_mode' with 'score_mode'.
5fill in blank
hard

Fill all three blanks to build a function score query with a script score, a filter, and a boost mode.

Elasticsearch
{
  "function_score": {
    "query": { "match_all": {} },
    "functions": [
      {
        "[1]": {
          "script": {
            "source": "doc['views'].value / 10"
          }
        },
        "filter": { "term": { "category": "[2]" } }
      }
    ],
    "[3]": "replace"
  }
}
Drag options to blanks, or click blank then click option'
Ascript_score
Btechnology
Cboost_mode
Dweight
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'weight' instead of 'script_score' for the function.
Confusing 'score_mode' with 'boost_mode'.