Bird
Raised Fist0
Elasticsearchquery~10 mins

Why relevance scoring ranks results in Elasticsearch - Test Your Understanding

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

Complete the code to specify the field to search in Elasticsearch.

Elasticsearch
{
  "query": {
    "match": {
      "[1]": "search text"
    }
  }
}
Drag options to blanks, or click blank then click option'
Aauthor
Bscore
Cdate
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using a numeric or date field instead of a text field.
2fill in blank
medium

Complete the code to add a boost factor to increase relevance of the field.

Elasticsearch
{
  "query": {
    "match": {
      "title": {
        "query": "search text",
        "[1]": 2
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aboost
Bscore
Cweight
Dpriority
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'score' or 'weight' which are not valid here.
3fill in blank
hard

Fix the error in the code to correctly use the function_score query for custom scoring.

Elasticsearch
{
  "query": {
    "function_score": {
      "query": { "match_all": {} },
      "[1]": [
        {
          "weight": 2
        }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Afilters
Bfunctions
Cboosts
Dscores
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'filters' or 'boosts' which are not valid keys here.
4fill in blank
hard

Fill both blanks to create a query that boosts documents with a specific tag.

Elasticsearch
{
  "query": {
    "function_score": {
      "query": { "match": { "content": "search" } },
      "[1]": [
        {
          "filter": { "term": { "tag": "important" } },
          "[2]": 3
        }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Afunctions
Bweight
Cboost
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'boost' instead of 'weight' inside functions.
5fill in blank
hard

Fill all three blanks to create a query that boosts documents with tag 'vip' and sorts by score descending.

Elasticsearch
{
  "query": {
    "function_score": {
      "query": { "match_all": {} },
      "[1]": [
        {
          "filter": { "term": { "tag": "vip" } },
          "[2]": 5
        }
      ]
    }
  },
  "sort": [
    { "[3]": { "order": "desc" } }
  ]
}
Drag options to blanks, or click blank then click option'
Afunctions
Bweight
C_score
Dboost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'boost' instead of 'weight' inside functions or sorting by a wrong field.

Practice

(1/5)
1. What does relevance scoring in Elasticsearch primarily determine?
easy
A. How well a document matches the search query
B. The size of the document
C. The date when the document was created
D. The number of fields in the document

Solution

  1. Step 1: Understand relevance scoring purpose

    Relevance scoring measures how closely a document matches the search query terms.
  2. Step 2: Compare options to scoring concept

    Only How well a document matches the search query relates to matching quality, others are unrelated to scoring.
  3. Final Answer:

    How well a document matches the search query -> Option A
  4. Quick Check:

    Relevance scoring = match quality [OK]
Hint: Relevance scoring ranks by match quality, not metadata [OK]
Common Mistakes:
  • Confusing scoring with document size
  • Thinking scoring depends on creation date
  • Assuming number of fields affects score
2. Which Elasticsearch query part directly influences relevance scoring?
easy
A. sort
B. match
C. filter
D. aggs

Solution

  1. Step 1: Identify query parts affecting scoring

    The match query scores documents based on how well they match the query text.
  2. Step 2: Differentiate from other parts

    filter and aggs do not affect scoring; sort orders results but doesn't calculate score.
  3. Final Answer:

    match -> Option B
  4. Quick Check:

    Match query = scoring influence [OK]
Hint: Match queries affect scoring; filters do not [OK]
Common Mistakes:
  • Thinking filters affect scoring
  • Confusing sort with scoring
  • Assuming aggregations influence score
3. Given this Elasticsearch query snippet, which document will rank higher?
{
  "query": {
    "match": {
      "title": "apple"
    }
  }
}
Documents: 1. {"title": "apple pie recipe"} 2. {"title": "banana apple smoothie"} 3. {"title": "fruit salad"}
medium
A. Document 3
B. Document 2
C. Document 1
D. All have the same score

Solution

  1. Step 1: Understand match query scoring

    Documents containing the exact term "apple" in the title get higher scores. Document 1 has "apple" at the start and is more focused.
  2. Step 2: Compare documents by term presence

    Document 1 has "apple" prominently; Document 2 has "apple" but mixed with "banana"; Document 3 lacks "apple".
  3. Final Answer:

    Document 1 -> Option C
  4. Quick Check:

    Exact term presence = higher score [OK]
Hint: Exact term in title ranks higher than partial or missing [OK]
Common Mistakes:
  • Assuming all documents score equally
  • Choosing document without the term
  • Ignoring term position and frequency
4. You wrote this Elasticsearch query but results are not ranked by relevance:
{
  "query": {
    "bool": {
      "filter": {
        "match": { "content": "coffee" }
      }
    }
  }
}
What is the main issue?
medium
A. "filter" does not calculate relevance scores
B. The "match" query is misspelled
C. The query must use "must_not" instead of "filter"
D. The field "content" does not exist

Solution

  1. Step 1: Understand bool query filter behavior

    The filter clause filters documents but does not affect relevance scoring.
  2. Step 2: Identify why scoring is missing

    Using filter with match disables scoring; to rank by relevance, use must instead.
  3. Final Answer:

    "filter" does not calculate relevance scores -> Option A
  4. Quick Check:

    Filter disables scoring, use must for relevance [OK]
Hint: Use must, not filter, for scoring queries [OK]
Common Mistakes:
  • Thinking filter affects scoring
  • Assuming match is misspelled
  • Ignoring bool query clause differences
5. You want to rank documents by relevance but also exclude those with "draft" status. Which query correctly ranks by relevance and filters out drafts?
{
  "query": {
    "bool": {
      "must": {
        "match": { "text": "Elasticsearch" }
      },
      "filter": {
        "term": { "status": "draft" }
      }
    }
  }
}
hard
A. Use "filter" for both match and filtering drafts
B. Use "filter" for match and "must" for filtering drafts
C. Use "should" for both match and filtering drafts
D. Use "must" for match and "must_not" for filtering drafts

Solution

  1. Step 1: Understand must and filter roles

    must runs scoring queries; filter filters without scoring; must_not excludes documents.
  2. Step 2: Apply exclusion for drafts

    To exclude drafts, use must_not with a term filter on status "draft"; keep must for scoring match query.
  3. Final Answer:

    Use "must" for match and "must_not" for filtering drafts -> Option D
  4. Quick Check:

    Must scores, must_not excludes [OK]
Hint: Use must for scoring, must_not to exclude unwanted docs [OK]
Common Mistakes:
  • Using filter to exclude documents (doesn't exclude)
  • Using should which affects scoring differently
  • Filtering match query disables scoring
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard