0
0
Elasticsearchquery~10 mins

Relevance score (_score) 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 retrieve the relevance score (_score) for each search hit.

Elasticsearch
{
  "query": {
    "match": {
      "message": "search text"
    }
  },
  "_source": ["message"],
  "fields": ["[1]"]
}
Drag options to blanks, or click blank then click option'
Arelevance
B_score
Cscore
Drank
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'score' without underscore
Using 'relevance' or 'rank' which are not valid fields
2fill in blank
medium

Complete the code to sort search results by their relevance score in descending order.

Elasticsearch
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {"[1]": {"order": "desc"}}
  ]
}
Drag options to blanks, or click blank then click option'
A_score
Bmessage
Ctimestamp
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by fields like 'message' or 'timestamp' instead of '_score'
Using ascending order which shows least relevant first
3fill in blank
hard

Fix the error in the query to correctly boost documents with the term 'urgent' to increase their relevance score.

Elasticsearch
{
  "query": {
    "bool": {
      "should": [
        {"match": {"message": "[1]"}},
        {"match": {"message": {"query": "urgent", "boost": 2}}}
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aimportant
Bhigh
Cnormal
Durgent
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different term than 'urgent' in the first match query
Not applying boost correctly
4fill in blank
hard

Fill both blanks to create a function score query that multiplies the relevance score by 3 for documents with 'priority' in the tag field.

Elasticsearch
{
  "query": {
    "function_score": {
      "query": {"match_all": {}},
      "functions": [
        {
          "filter": {"term": {"tags": "[1]"}},
          "weight": [2]
        }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Apriority
Burgent
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong tag name in filter
Using incorrect weight value
5fill in blank
hard

Fill all three blanks to build a query that boosts documents containing 'error' in the message field by 5 and sorts results by relevance score descending.

Elasticsearch
{
  "query": {
    "function_score": {
      "query": {"match": {"message": "[1]"}},
      "boost": [2],
      "boost_mode": "multiply"
    }
  },
  "sort": [
    {"[3]": {"order": "desc"}}
  ]
}
Drag options to blanks, or click blank then click option'
Aerror
B5
C_score
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong term in match query
Incorrect boost value
Sorting by wrong field