0
0
Elasticsearchquery~20 mins

Constant score query in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Constant Score 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 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
    }
  }
}
AEach matching document has a score of 5
BEach matching document has a score equal to the term frequency of "active"
CEach matching document has a score of 1
DEach matching document has a score of 0
Attempts:
2 left
💡 Hint
Remember that constant_score sets the score to the boost value for all matching documents.
🧠 Conceptual
intermediate
1: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?
ATo perform full-text search with relevance scoring
BTo sort documents by their field values
CTo assign the same score to all matching documents regardless of relevance
DTo update documents in the index
Attempts:
2 left
💡 Hint
Think about when you want to ignore relevance and just filter with a fixed score.
🔧 Debug
advanced
2: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"
    }
  }
}
ASyntaxError: missing comma after filter
BTypeError: boost must be a number, not a string
CNo error, query runs successfully
DRuntimeError: match query not allowed inside constant_score
Attempts:
2 left
💡 Hint
Check the type of the boost value.
📝 Syntax
advanced
2: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.
A{ "query": { "constant_score": { "filter": { "range": { "age": { "greater_than": 30 } } }, "boost": 3 } } }
B{ "query": { "constant_score": { "filter": { "range": { "age": { "min": 30 } } }, "boost": 3 } } }
C{ "query": { "constant_score": { "filter": { "range": { "age": { "gte": 30 } } }, "boost": 3 } } }
D{ "query": { "constant_score": { "filter": { "range": { "age": { "gt": 30 } } }, "boost": 3 } } }
Attempts:
2 left
💡 Hint
Check the correct range operator for greater than in Elasticsearch.
🚀 Application
expert
2: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
    }
  }
}
A200
B1000
C0
D800
Attempts:
2 left
💡 Hint
Only documents matching the filter get the boost score.