Bird
Raised Fist0
Elasticsearchquery~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of a multi-match query in Elasticsearch?
easy
A. To search multiple fields with a single query
B. To update multiple documents at once
C. To delete multiple indexes simultaneously
D. To create multiple indexes in one request

Solution

  1. Step 1: Understand the multi-match query concept

    A multi-match query allows searching across several fields in one query, making it easier to find matches in different parts of documents.
  2. Step 2: Compare with other options

    The other options describe operations like creating indexes, updating documents, or deleting indexes, which are not the purpose of multi-match queries.
  3. Final Answer:

    To search multiple fields with a single query -> Option A
  4. Quick Check:

    Multi-match = search multiple fields [OK]
Hint: Multi-match searches many fields at once [OK]
Common Mistakes:
  • Confusing multi-match with update or delete operations
  • Thinking it creates or deletes indexes
  • Assuming it searches only one field
2. Which of the following is the correct syntax to perform a multi-match query searching for the word "apple" in fields "title" and "description"?
easy
A. { "multi_match": { "query": "apple", "fields": ["title", "description"] } }
B. { "match": { "query": "apple", "fields": ["title", "description"] } }
C. { "multi_match": { "fields": ["title", "description"] } }
D. { "multi_match": { "query": "apple" } }

Solution

  1. Step 1: Identify required keys in multi-match query

    A multi-match query requires a "query" key with the search term and a "fields" key listing the fields to search.
  2. Step 2: Check each option for correct syntax

    { "multi_match": { "query": "apple", "fields": ["title", "description"] } } correctly includes both "query" and "fields" keys. { "match": { "query": "apple", "fields": ["title", "description"] } } uses "match" instead of "multi_match". { "multi_match": { "fields": ["title", "description"] } } misses the "query" key. { "multi_match": { "query": "apple" } } misses the "fields" key.
  3. Final Answer:

    { "multi_match": { "query": "apple", "fields": ["title", "description"] } } -> Option A
  4. Quick Check:

    multi_match needs query and fields [OK]
Hint: multi_match needs both query and fields keys [OK]
Common Mistakes:
  • Using 'match' instead of 'multi_match'
  • Omitting the 'query' key
  • Omitting the 'fields' key
3. Given this multi-match query, what will be the effect?
{
  "multi_match": {
    "query": "quick fox",
    "fields": ["title", "content"],
    "type": "phrase"
  }
}
medium
A. Searches only the title field for the phrase "quick fox"
B. Searches for documents containing "quick" or "fox" anywhere in title or content
C. Searches for documents where "quick fox" appears as a phrase in either title or content
D. Searches for documents with exact match "quick fox" in all fields

Solution

  1. Step 1: Understand the 'type' parameter in multi-match

    The "type": "phrase" option makes the query look for the exact phrase "quick fox" in the specified fields.
  2. Step 2: Check fields and matching behavior

    The fields are "title" and "content", so the phrase must appear in either field, not necessarily both.
  3. Final Answer:

    Searches for documents where "quick fox" appears as a phrase in either title or content -> Option C
  4. Quick Check:

    type phrase = exact phrase match in fields [OK]
Hint: type phrase means exact phrase search [OK]
Common Mistakes:
  • Thinking it searches for words separately (not phrase)
  • Assuming it searches only one field
  • Believing it requires phrase in all fields
4. Identify the error in this multi-match query:
{
  "multi_match": {
    "query": "data",
    "fields": "title, description"
  }
}
medium
A. "query" should be an array of words
B. "fields" should be an array, not a string
C. "multi_match" should be "match"
D. "fields" should be omitted for multi-match

Solution

  1. Step 1: Check the type of "fields" value

    The "fields" key must be an array of field names, not a single string with commas.
  2. Step 2: Validate other keys

    The "query" key is correctly a string. "multi_match" is the correct query type. "fields" should not be omitted.
  3. Final Answer:

    "fields" should be an array, not a string -> Option B
  4. Quick Check:

    fields must be array, not comma string [OK]
Hint: Fields must be an array, not a comma string [OK]
Common Mistakes:
  • Passing fields as a comma-separated string
  • Changing multi_match to match incorrectly
  • Thinking query must be an array
5. You want to search for the term "coffee" giving higher importance to the "title" field than "description" and "tags" fields. Which multi-match query correctly applies this weighting?
hard
A. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "boost": 3 } }
B. { "multi_match": { "query": "coffee", "fields": ["title", "description^3", "tags"] } }
C. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "type": "boost" } }
D. { "multi_match": { "query": "coffee", "fields": ["title^3", "description", "tags"] } }

Solution

  1. Step 1: Understand field boosting syntax

    To give more importance to a field, add a caret (^) and a boost number after the field name, e.g., "title^3".
  2. Step 2: Check each option for correct boosting

    { "multi_match": { "query": "coffee", "fields": ["title^3", "description", "tags"] } } boosts "title" by 3, others default. { "multi_match": { "query": "coffee", "fields": ["title", "description^3", "tags"] } } boosts "description" incorrectly. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "boost": 3 } } tries to boost all fields equally with "boost" key, which is invalid here. { "multi_match": { "query": "coffee", "fields": ["title", "description", "tags"], "type": "boost" } } uses an invalid "type" value.
  3. Final Answer:

    { "multi_match": { "query": "coffee", "fields": ["title^3", "description", "tags"] } } -> Option D
  4. Quick Check:

    Use ^number to boost fields [OK]
Hint: Boost fields with ^number after field name [OK]
Common Mistakes:
  • Boosting wrong field
  • Using 'boost' key incorrectly
  • Setting invalid 'type' value
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard