A constant score query lets you find documents that match a condition and gives them all the same score. This is useful when you want to filter results without changing their ranking.
When you want to filter documents by a condition but don't care about scoring differences.
When you want to improve search speed by skipping score calculations.
When you want to combine filters with other queries but keep scores constant.
When you want to boost documents equally based on a filter.
When you want to apply a filter inside a query without affecting relevance scores.
A. The boost value should be a number, not a string
B. The filter key should be replaced with query
C. The terms query cannot be used inside constant_score
D. The tags field should be inside a match query
Solution
Step 1: Check boost data type
The boost parameter must be a numeric value, not a string. Here, "2" is a string, which is invalid.
Step 2: Validate filter and terms usage
Using "filter" with a "terms" query is valid syntax, so no error there.
Final Answer:
The boost value should be a number, not a string -> Option A
Quick Check:
boost must be numeric, not string [OK]
Hint: Boost must be a number, not quoted string [OK]
Common Mistakes:
Using string for boost instead of number
Replacing filter with query incorrectly
Misunderstanding terms query usage
5. You want to find all documents where status is published and boost their score by 5, but keep all matched documents scored equally. Which query correctly achieves this?
hard
A. { "match": { "status": "published", "boost": 5 } }
To keep scores equal and apply a boost, use constant_score with a filter clause and boost parameter.
Step 2: Validate correct syntax
{ "constant_score": { "filter": { "term": { "status": "published" } }, "boost": 5 } } uses "filter" with a term query and numeric boost, which is the correct syntax.
Step 3: Check other options
{ "bool": { "must": { "term": { "status": "published" } }, "boost": 5 } } uses bool query which scores by relevance, not constant. { "match": { "status": "published", "boost": 5 } } is a match query with boost but scores vary. { "constant_score": { "query": { "term": { "status": "published" } }, "boost": 5 } } incorrectly uses "query" instead of "filter" inside constant_score.