0
0
Elasticsearchquery~20 mins

Dis max query in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dis Max Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the score behavior of this dis_max query?
Given the following Elasticsearch dis_max query, what will be the _score of a document that matches both clauses equally with a tie_breaker of 0.3?
Elasticsearch
{
  "query": {
    "dis_max": {
      "tie_breaker": 0.3,
      "queries": [
        { "match": { "title": "apple" } },
        { "match": { "description": "apple" } }
      ]
    }
  }
}
AThe score is the sum of both match scores without any multiplier.
BThe score is the average of the two match scores.
CThe score is the maximum score of the two matches plus 0.3 times the other score.
DThe score is only the maximum score of the two matches, ignoring the tie_breaker.
Attempts:
2 left
💡 Hint
Remember that dis_max uses the highest score plus a fraction of the others based on tie_breaker.
🧠 Conceptual
intermediate
1:30remaining
Which use case best fits a dis_max query?
Which scenario is the best reason to use a dis_max query in Elasticsearch?
AYou want to find documents matching any of several queries but prefer the highest scoring match with some bonus for others.
BYou want to boost documents that match all queries by multiplying their scores.
CYou want to filter documents strictly matching all queries.
DYou want to combine multiple queries and sum all their scores equally.
Attempts:
2 left
💡 Hint
Dis max is about picking the best match with some influence from others.
🔧 Debug
advanced
2:30remaining
Why does this dis_max query ignore the tie_breaker?
Consider this dis_max query: { "query": { "dis_max": { "tie_breaker": 0.5, "queries": [ { "match": { "field1": "test" } }, { "match": { "field2": "test" } } ] } } } Why might the tie_breaker have no effect on the scoring?
ABecause only one of the queries matches the document, so no tie breaker is applied.
BBecause the tie_breaker value must be between 0 and 1 exclusive, and 0.5 is invalid.
CBecause dis_max requires a minimum_should_match parameter to apply tie_breaker.
DBecause the queries are inside a bool filter, which disables scoring.
Attempts:
2 left
💡 Hint
Tie breaker only affects when multiple queries match.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this dis_max query
Which option contains a syntax error in the dis_max query?
Elasticsearch
{
  "query": {
    "dis_max": {
      "tie_breaker": 0.2,
      "queries": [
        { "match": { "field": "value1" } },
        { "match": { "field": "value2" } }
      ]
    }
  }
}
A{ "dis_max": { "tieBreaker": 0.2, "queries": [ { "match": { "field": "value1" } }, { "match": { "field": "value2" } } ] } }
B{ "dis_max": { "tie_breaker": 0.2, "query": [ { "match": { "field": "value1" } }, { "match": { "field": "value2" } } ] } }
C{ "dis_max": { "tie_breaker": 0.2, "queries": [ { "match": { "field": "value1" } }, { "match": { "field": "value2" } } ] } }
D} } ] } } "2eulav" :"dleif" { :"hctam" { ,} } "1eulav" :"dleif" { :"hctam" { [ :"seireuq" ,2.0 :"rekaerb_eit" { :"xam_sid" {
Attempts:
2 left
💡 Hint
Check the key name for the list of queries inside dis_max.
🚀 Application
expert
3:00remaining
How to combine dis_max with boosting for best relevance?
You want to search documents matching either 'title' or 'content' fields. You want the best match to score highest but also boost matches in 'title' by 2x. Which query achieves this?
A
{
  "dis_max": {
    "tie_breaker": 0.1,
    "queries": [
      { "match": { "title": "search" } },
      { "match": { "content": { "query": "search", "boost": 2 } } }
    ]
  }
}
B
{
  "bool": {
    "should": [
      { "match": { "title": { "query": "search", "boost": 2 } } },
      { "match": { "content": "search" } }
    ]
  }
}
C
{
  "function_score": {
    "query": {
      "dis_max": {
        "tie_breaker": 0.1,
        "queries": [
          { "match": { "title": "search" } },
          { "match": { "content": "search" } }
        ]
      }
    },
    "boost": 2
  }
}
D
{
  "dis_max": {
    "tie_breaker": 0.1,
    "queries": [
      { "match": { "title": { "query": "search", "boost": 2 } } },
      { "match": { "content": "search" } }
    ]
  }
}
Attempts:
2 left
💡 Hint
Boost inside the match query affects that field's score before dis_max combines them.