0
0
Elasticsearchquery~10 mins

Dis max query in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Dis max query
Start Dis Max Query
Evaluate Each Query
Calculate Scores
Select Max Score
Add Tie Breaker Score
Return Final Score
Dis max query runs multiple queries, picks the highest score, adds a tie breaker, and returns the final score.
Execution Sample
Elasticsearch
{
  "dis_max": {
    "queries": [
      { "match": { "title": "apple" } },
      { "match": { "description": "apple" } }
    ],
    "tie_breaker": 0.3
  }
}
This query searches 'apple' in title and description fields, picks the best score, and adds 30% of other scores.
Execution Table
StepQuery EvaluatedScoreMax Score So FarTie Breaker ContributionFinal Score
1match title: apple2.02.002.0
2match description: apple1.52.00.452.45
3End-2.00.452.45
💡 All queries evaluated; max score 2.0 plus tie breaker 0.45 gives final score 2.45
Variable Tracker
VariableStartAfter Query 1After Query 2Final
max_score02.02.02.0
tie_breaker_sum001.51.5
final_score02.02.452.45
Key Moments - 2 Insights
Why does the final score include a tie breaker value?
The tie breaker adds a fraction of the other query scores to the max score, as shown in step 2 of the execution_table, to improve relevance when multiple queries match.
What if one query score is much higher than others?
The max score dominates the final score, but the tie breaker still adds a small part of other scores, ensuring they influence ranking slightly (see variable_tracker final values).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the tie breaker contribution?
A0
B0.45
C1.5
D2.0
💡 Hint
Check the 'Tie Breaker Contribution' column at step 2 in the execution_table.
At which step does the max score get set to 2.0?
AStep 1
BStep 2
CStep 3
DStart
💡 Hint
Look at the 'Max Score So Far' column in the execution_table.
If tie_breaker was 0, what would the final score be after step 2?
A1.5
B2.45
C2.0
D0
💡 Hint
Refer to how tie breaker adds to final score in the execution_table and variable_tracker.
Concept Snapshot
Dis max query runs multiple queries,
picks the highest score,
adds tie_breaker * sum of other scores,
and returns the combined final score.
Use tie_breaker to balance relevance from multiple fields.
Full Transcript
The Dis max query in Elasticsearch evaluates multiple queries and picks the highest score among them. It then adds a tie breaker value, which is a fraction of the other query scores, to the max score. This helps improve relevance when multiple queries match. In the example, two queries search for 'apple' in title and description fields. The first query scores 2.0, the second 1.5. The max score is 2.0. The tie breaker is 0.3, so 0.3 times 1.5 equals 0.45. Adding this to 2.0 gives a final score of 2.45. Variables like max_score, tie_breaker_sum, and final_score update step by step. This process ensures the best matching query dominates but others still influence the result slightly.