0
0
Elasticsearchquery~10 mins

Match query in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Match query
Receive user text input
Analyze text: tokenize, lowercase
Search index for matching tokens
Score documents by relevance
Return ranked results
The match query takes user text, breaks it into words, searches the index for those words, scores documents by relevance, and returns the best matches.
Execution Sample
Elasticsearch
{
  "query": {
    "match": {
      "message": "quick brown fox"
    }
  }
}
This query searches the 'message' field for documents matching the words 'quick brown fox'.
Execution Table
StepActionInput/ConditionResult/Output
1Receive query text"quick brown fox"Text ready for analysis
2Analyze textTokenize and lowercase["quick", "brown", "fox"]
3Search indexLook for documents with tokensDocuments containing any of the tokens
4Score documentsCalculate relevance based on token matchesDocuments ranked by score
5Return resultsTop ranked documentsList of matching documents shown
💡 All steps complete, results returned to user
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
query_text"quick brown fox""quick brown fox""quick brown fox""quick brown fox""quick brown fox"
tokens[]["quick", "brown", "fox"]["quick", "brown", "fox"]["quick", "brown", "fox"]["quick", "brown", "fox"]
matched_docs[][]["doc1", "doc2", "doc3"]["doc1(score=3)", "doc2(score=2)", "doc3(score=1)"]["doc1", "doc2", "doc3"]
Key Moments - 3 Insights
Why does the match query break the input text into tokens?
Because the match query analyzes the text to find individual words (tokens) to search for, as shown in step 2 of the execution_table where the text is tokenized into ["quick", "brown", "fox"].
Does the match query look for the exact phrase 'quick brown fox' or individual words?
It looks for individual words, not the exact phrase. The tokens are searched separately as shown in step 3 where documents containing any of the tokens are found.
How are documents ranked in the match query results?
Documents are scored based on how many tokens they contain and their relevance, as shown in step 4 where documents have scores like 3, 2, and 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what tokens are generated after step 2?
A["quick brown fox"]
B["quick", "brown", "fox"]
C["Quick", "Brown", "Fox"]
D[]
💡 Hint
Check the 'Result/Output' column in row for step 2 in execution_table
At which step are documents scored by relevance?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Look at the 'Action' column in execution_table to find scoring step
If the input text was changed to 'lazy dog', how would the tokens in variable_tracker change after step 2?
A["lazy dog"]
B["quick", "brown", "fox"]
C["lazy", "dog"]
D[]
💡 Hint
Refer to the 'tokens' row in variable_tracker after step 2
Concept Snapshot
Match query syntax:
{
  "query": { "match": { "field": "text" } }
}

Behavior:
- Analyzes input text into tokens
- Searches for documents containing tokens
- Scores documents by relevance
- Returns ranked results

Key rule: Match query searches words, not exact phrases.
Full Transcript
The match query in Elasticsearch takes the user's input text and breaks it into smaller parts called tokens. These tokens are usually words in lowercase. Then, it searches the index for documents that contain any of these tokens. Each document is scored based on how many tokens it contains and how relevant they are. Finally, the query returns a list of documents ranked by their scores. For example, if the input is 'quick brown fox', the query looks for documents containing 'quick', 'brown', or 'fox' and ranks them accordingly. This process involves analyzing the text, searching, scoring, and returning results step-by-step.