0
0
Elasticsearchquery~10 mins

Multi-match query in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Multi-match query
Start Query
Specify Multi-match Query
Provide Search Text
Define Fields to Search
Elasticsearch Searches All Fields
Combine Scores from Fields
Return Best Matches
End
The multi-match query takes a search text and looks for it across multiple fields, combining scores to find the best matches.
Execution Sample
Elasticsearch
{
  "query": {
    "multi_match": {
      "query": "apple",
      "fields": ["title", "description"],
      "type": "most_fields"
    }
  }
}
This query searches for the word 'apple' in both the 'title' and 'description' fields.
Execution Table
StepActionInputFields SearchedResulting ScoreNotes
1Start multi-match queryquery='apple'title, descriptionN/AQuery initialized
2Search 'apple' in 'title'appletitle0.8Found 'apple' in title with score 0.8
3Search 'apple' in 'description'appledescription0.5Found 'apple' in description with score 0.5
4Combine scores0.8 + 0.5title, description1.3Scores combined for final relevance
5Return document with combined scorescore=1.3title, description1.3Document returned as a match
6EndNo more docsN/AN/AQuery execution complete
💡 All specified fields searched and scores combined; query ends after returning matches.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
queryN/Aappleappleappleapple
fieldsN/A[title, description][title, description][title, description][title, description]
score_title00.80.80.80.8
score_description000.50.50.5
combined_score0001.31.3
Key Moments - 2 Insights
Why does the multi-match query combine scores from multiple fields?
Because it searches the same query text in each specified field separately and then adds their relevance scores to find the best overall match, as shown in steps 2, 3, and 4 of the execution table.
What happens if the query text is found in only one field?
Only that field contributes a score, and the combined score equals that single field's score. This is implied in the execution table where scores are added only if found.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the combined score after searching both fields?
A0.5
B0.8
C1.3
D2.0
💡 Hint
Check the 'Combine scores' row (Step 4) in the execution table.
At which step does Elasticsearch search the 'description' field?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Look at the 'Action' column for searching fields in the execution table.
If the query text was not found in 'title', how would the combined score change?
AIt would be 1.3
BIt would be 0.5
CIt would be 0
DIt would be 0.8
💡 Hint
Refer to the variable_tracker for scores after each step.
Concept Snapshot
Multi-match query syntax:
{
  "query": {
    "multi_match": {
      "query": "text",
      "fields": ["field1", "field2"],
      "type": "most_fields"
    }
  }
}

Behavior: Searches given text across multiple fields, combines relevance scores, and returns best matches.
Key rule: Scores from each field add up to determine overall relevance.
Full Transcript
The multi-match query in Elasticsearch lets you search for a word or phrase across several fields at once. You start by specifying the query text and the fields you want to search. Elasticsearch then looks for the text in each field separately and gives each match a score. These scores are added together to find the best overall matches. For example, if the word 'apple' is found in the 'title' field with a score of 0.8 and in the 'description' field with a score of 0.5, the combined score is 1.3. The documents with the highest combined scores are returned as the best matches. This way, you can search multiple parts of your data with one query and get results ranked by how well they match across all fields.