Bird
Raised Fist0
Elasticsearchquery~20 mins

Boosting query in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Boosting Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this boosting query?
Given the following Elasticsearch boosting query, what documents will be boosted and how?
Elasticsearch
{
  "query": {
    "boosting": {
      "positive": {
        "match": {"title": "apple"}
      },
      "negative": {
        "match": {"title": "banana"}
      },
      "negative_boost": 0.2
    }
  }
}
ADocuments containing both "apple" and "banana" are boosted equally.
BDocuments containing "apple" in title are boosted; documents containing "banana" have their score reduced by 80%.
CDocuments containing "banana" are boosted; documents containing "apple" have their score reduced by 80%.
DDocuments containing "apple" or "banana" are excluded from results.
Attempts:
2 left
💡 Hint
Remember that the positive query boosts scores, and the negative query reduces scores by the negative_boost factor.
🧠 Conceptual
intermediate
1:30remaining
Which statement best describes the purpose of the negative_boost parameter?
In an Elasticsearch boosting query, what does the negative_boost parameter do?
AIt decreases the score of documents matching the negative query by a factor.
BIt increases the score of documents matching the negative query.
CIt excludes documents matching the negative query from the results.
DIt sets the minimum score for documents to be included.
Attempts:
2 left
💡 Hint
Think about how the negative query affects scoring.
🔧 Debug
advanced
2:00remaining
Why does this boosting query cause a syntax error?
Identify the error in this boosting query and its cause: { "query": { "boosting": { "positive": { "match": {"content": "python"} }, "negative": { "match": {"content": "java"} }, "negative_boost": "0.5" } } }
AThe negative query is missing a closing bracket.
BThe positive query must be a term query, not match.
Cnegative_boost should be a number, not a string.
DThe boosting query requires a minimum_should_match parameter.
Attempts:
2 left
💡 Hint
Check the data type of negative_boost.
❓ Predict Output
advanced
2:00remaining
What is the effect of this boosting query on document scores?
Consider this boosting query: { "query": { "boosting": { "positive": { "term": {"category": "electronics"} }, "negative": { "term": {"brand": "generic"} }, "negative_boost": 0.1 } } } What happens to documents in the "electronics" category with brand "generic"?
ATheir score is multiplied by 0.1, reducing it significantly.
BTheir score is boosted twice, increasing it.
CThey are excluded from the results.
DTheir score remains unchanged.
Attempts:
2 left
💡 Hint
Both positive and negative queries can match the same document.
🚀 Application
expert
2:30remaining
How many documents will have their scores reduced by this boosting query?
Given an index with 1000 documents, 300 contain "python" in the "tags" field, 150 contain "beginner" in the "tags" field, and 50 contain both. Using this boosting query: { "query": { "boosting": { "positive": { "match": {"tags": "python"} }, "negative": { "match": {"tags": "beginner"} }, "negative_boost": 0.3 } } } How many documents will have their scores reduced by the negative_boost?
A200 documents
B350 documents
C50 documents
D150 documents
Attempts:
2 left
💡 Hint
Only documents matching the negative query have their scores reduced.

Practice

(1/5)
1. What is the main purpose of a boosting query in Elasticsearch?
easy
A. To filter out documents without a specific field
B. To sort results alphabetically
C. To increase the relevance score of some results and decrease others
D. To aggregate data by terms

Solution

  1. Step 1: Understand boosting query purpose

    A boosting query is designed to adjust the relevance scores of search results by raising some and lowering others.
  2. Step 2: Compare with other query types

    Sorting alphabetically, filtering, and aggregating are different Elasticsearch features unrelated to boosting.
  3. Final Answer:

    To increase the relevance score of some results and decrease others -> Option C
  4. Quick Check:

    Boosting query = Adjust relevance scores [OK]
Hint: Boosting changes scores, not sorting or filtering [OK]
Common Mistakes:
  • Confusing boosting with sorting
  • Thinking boosting filters documents
  • Mixing boosting with aggregation
2. Which of the following is the correct syntax snippet for a boosting query in Elasticsearch?
easy
A. { "boosting": { "positive": { "term": { "field": "value" } }, "negative": { "term": { "field": "other" } } } }
B. { "boost": { "match": { "field": "value" }, "boost_factor": 2 } }
C. { "boosting_query": { "positive": { "term": { "field": "value" } }, "negative": { "term": { "field": "other" } } } }
D. { "boosting": { "positive": { "match": { "field": "value" } }, "negative": { "match": { "field": "other" } }, "negative_boost": 0.5 } }

Solution

  1. Step 1: Identify correct boosting query structure

    The correct syntax uses the "boosting" key with "positive", "negative", and "negative_boost" fields.
  2. Step 2: Check each option

    The snippet using "boosting" with "positive" match query, "negative" match query, and "negative_boost": 0.5 matches the correct structure. Others miss "negative_boost" or use incorrect keys like "boost" or "boosting_query".
  3. Final Answer:

    { "boosting": { "positive": { "match": { "field": "value" } }, "negative": { "match": { "field": "other" } }, "negative_boost": 0.5 } } -> Option D
  4. Quick Check:

    Boosting query syntax = { "boosting": { "positive": { "match": { "field": "value" } }, "negative": { "match": { "field": "other" } }, "negative_boost": 0.5 } } [OK]
Hint: Look for "boosting" with positive, negative, and negative_boost keys [OK]
Common Mistakes:
  • Using wrong key names like "boost" or "boosting_query"
  • Omitting "negative_boost"
  • Using incorrect query types inside positive/negative
3. Given this boosting query, what will happen to documents matching the negative query?
{
  "boosting": {
    "positive": { "match": { "title": "apple" } },
    "negative": { "match": { "title": "banana" } },
    "negative_boost": 0.3
  }
}
medium
A. Their relevance scores will be increased by 0.3
B. Their relevance scores will be decreased by multiplying by 0.3
C. They will be excluded from results
D. They will have the same score as positive matches

Solution

  1. Step 1: Understand negative_boost effect

    The negative_boost value multiplies the score of documents matching the negative query, lowering their relevance.
  2. Step 2: Apply to given query

    Documents matching "banana" will have their scores multiplied by 0.3, reducing their rank but not excluding them.
  3. Final Answer:

    Their relevance scores will be decreased by multiplying by 0.3 -> Option B
  4. Quick Check:

    negative_boost multiplies score down [OK]
Hint: Negative matches get score multiplied by negative_boost < 1 [OK]
Common Mistakes:
  • Thinking negative_boost adds to score
  • Assuming negative matches are filtered out
  • Confusing negative_boost with positive boost
4. Identify the error in this boosting query:
{
  "boosting": {
    "positive": { "match": { "content": "dog" } },
    "negative": { "match": { "content": "cat" } }
  }
}
medium
A. Missing "negative_boost" field
B. Incorrect query type inside positive
C. Wrong key name "boosting" should be "boost"
D. Positive and negative queries cannot use the same field

Solution

  1. Step 1: Check required fields in boosting query

    A boosting query requires "positive", "negative", and "negative_boost" fields to work correctly.
  2. Step 2: Identify missing element

    The provided query lacks the "negative_boost" field, which defines how much to reduce negative matches.
  3. Final Answer:

    Missing "negative_boost" field -> Option A
  4. Quick Check:

    Boosting query needs negative_boost [OK]
Hint: Always include negative_boost in boosting queries [OK]
Common Mistakes:
  • Omitting negative_boost
  • Using wrong key names
  • Assuming same field usage is invalid
5. You want to boost documents containing "premium" in the category field and reduce scores of documents containing "basic" in the same field by half. Which boosting query correctly achieves this?
hard
A. { "boosting": { "positive": { "term": { "category": "premium" } }, "negative": { "term": { "category": "basic" } }, "negative_boost": 0.5 } }
B. { "boosting": { "positive": { "match": { "category": "premium" } }, "negative": { "match": { "category": "basic" } }, "negative_boost": 2 } }
C. { "boost": { "term": { "category": "premium" }, "boost_factor": 2 } }
D. { "boosting": { "positive": { "term": { "category": "basic" } }, "negative": { "term": { "category": "premium" } }, "negative_boost": 0.5 } }

Solution

  1. Step 1: Identify positive and negative queries

    Positive query should match "premium" category to boost, negative query should match "basic" to reduce score.
  2. Step 2: Check negative_boost value

    Negative boost of 0.5 reduces scores of negative matches by half, which matches the requirement.
  3. Step 3: Verify options

    { "boosting": { "positive": { "term": { "category": "premium" } }, "negative": { "term": { "category": "basic" } }, "negative_boost": 0.5 } } correctly uses term queries and negative_boost 0.5. Other options either use negative_boost greater than 1, are not boosting queries, or reverse positive and negative.
  4. Final Answer:

    { "boosting": { "positive": { "term": { "category": "premium" } }, "negative": { "term": { "category": "basic" } }, "negative_boost": 0.5 } } -> Option A
  5. Quick Check:

    Positive = premium, negative = basic, negative_boost = 0.5 [OK]
Hint: Positive boosts, negative reduces with negative_boost < 1 [OK]
Common Mistakes:
  • Swapping positive and negative queries
  • Using negative_boost greater than 1
  • Using boost instead of boosting query
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