0
0
Elasticsearchquery~20 mins

Relevance score (_score) in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Relevance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the _score of a match query with exact term match?
Given the following Elasticsearch query, what will be the _score of the matched document relative to a document that does not contain the term?
Elasticsearch
{
  "query": {
    "match": {
      "title": "Elasticsearch"
    }
  }
}
ANull because _score is not returned by default
B-1 because the term is matched negatively
CA positive float value indicating relevance, higher than zero
DAlways zero because match queries do not calculate _score
Attempts:
2 left
💡 Hint
Think about how Elasticsearch scores documents based on term frequency and inverse document frequency.
🧠 Conceptual
intermediate
2:00remaining
How does Elasticsearch calculate the _score for a multi-match query?
In Elasticsearch, when you use a multi-match query across multiple fields, how is the _score for each document computed?
AIt ignores field matches and assigns a fixed _score
BIt sums the individual _scores from each field where the term matches
CIt averages the _scores from all fields regardless of matches
DIt takes the maximum _score from any single field match
Attempts:
2 left
💡 Hint
Consider how relevance from multiple fields contributes to the overall score.
🔧 Debug
advanced
2:00remaining
Why does this bool query always return zero _score?
Examine the following Elasticsearch query. Why does it always return documents with _score equal to zero?
Elasticsearch
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "status": "active" } },
        { "term": { "category": "books" } }
      ]
    }
  }
}
ABecause filters do not contribute to _score, so all scores are zero
BBecause term queries inside filter always return zero hits
CBecause bool queries require must clauses to calculate _score
DBecause the index is empty, so no scores are calculated
Attempts:
2 left
💡 Hint
Think about the difference between filter and must clauses in bool queries.
📝 Syntax
advanced
2:00remaining
Which query syntax correctly boosts the _score of documents matching 'python'?
Select the Elasticsearch query syntax that correctly boosts the _score of documents containing the term 'python' in the 'description' field.
A{ "match": { "description": { "boost": 2.0, "query": "python" } } }
B{ "match": { "description": "python", "boost": 2.0 } }
C{ "match": { "description": { "query": "python" }, "boost": 2.0 } }
D{ "match": { "description": { "query": "python", "boost": 2.0 } } }
Attempts:
2 left
💡 Hint
Check the correct placement of the boost parameter inside the match query object.
🚀 Application
expert
3:00remaining
How to combine function_score with match query to boost recent documents?
You want to boost the _score of documents matching 'data science' in the 'content' field, but also boost documents published in the last 30 days. Which Elasticsearch query achieves this?
A
{
  "function_score": {
    "query": { "match": { "content": "data science" } },
    "functions": [
      {
        "filter": {
          "range": { "publish_date": { "gte": "now-30d/d" } }
        },
        "weight": 3
      }
    ],
    "boost_mode": "multiply"
  }
}
B
{
  "query": {
    "bool": {
      "must": { "match": { "content": "data science" } },
      "should": {
        "range": { "publish_date": { "gte": "now-30d/d" } }
      }
    }
  }
}
C
{
  "function_score": {
    "query": { "match": { "content": "data science" } },
    "boost": 3,
    "filter": {
      "range": { "publish_date": { "gte": "now-30d/d" } }
    }
  }
}
D
{
  "query": {
    "match": {
      "content": {
        "query": "data science",
        "boost": 3
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Use function_score to combine query relevance with custom boosting based on a filter.