Challenge - 5 Problems
Constant Score Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this constant_score query?
Given the following Elasticsearch query, what is the score of each document matching the filter?
Elasticsearch
{
"query": {
"constant_score": {
"filter": {
"term": { "status": "active" }
},
"boost": 5
}
}
}Attempts:
2 left
💡 Hint
Remember that constant_score sets the score to the boost value for all matching documents.
✗ Incorrect
The constant_score query wraps a filter and assigns a fixed score (boost) to all documents matching the filter, ignoring relevance scoring.
🧠 Conceptual
intermediate1:30remaining
Why use a constant_score query instead of a match query?
Which of the following is the main reason to use a constant_score query?
Attempts:
2 left
💡 Hint
Think about when you want to ignore relevance and just filter with a fixed score.
✗ Incorrect
Constant_score queries are used when you want to filter documents and assign them a fixed score, ignoring the usual relevance calculations.
🔧 Debug
advanced2:00remaining
Identify the error in this constant_score query
What error will this query produce?
Elasticsearch
{
"query": {
"constant_score": {
"filter": {
"match": { "title": "Elasticsearch" }
},
"boost": "high"
}
}
}Attempts:
2 left
💡 Hint
Check the type of the boost value.
✗ Incorrect
The boost parameter must be a numeric value. Using a string like "high" causes a type error.
📝 Syntax
advanced2:00remaining
Which option is the correct syntax for a constant_score query with a range filter?
Select the valid constant_score query that filters documents with age greater than 30 and assigns a boost of 3.
Attempts:
2 left
💡 Hint
Check the correct range operator for greater than in Elasticsearch.
✗ Incorrect
Elasticsearch range query uses 'gt' for greater than (strictly > 30) and 'gte' for greater than or equal to (>= 30). The question specifies 'greater than 30', so 'gt' (option D) is correct. Option D uses invalid 'min', option D uses invalid 'greater_than', option D uses 'gte' which includes 30.
🚀 Application
expert2:30remaining
How many documents will be scored with boost 10 in this query?
Assume the index has 1000 documents. 200 have field "category" equal to "books". What is the number of documents that will have a score of 10 after running this query?
Elasticsearch
{
"query": {
"constant_score": {
"filter": {
"term": { "category": "books" }
},
"boost": 10
}
}
}Attempts:
2 left
💡 Hint
Only documents matching the filter get the boost score.
✗ Incorrect
Only the 200 documents with category 'books' match the filter and get the constant score of 10. Others are excluded.