0
0
Elasticsearchquery~10 mins

Term query in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Term query
Start: Receive Query
Parse Term Query
Search Exact Term in Index
Match Documents Found?
NoReturn Empty Result
Yes
Return Matching Documents
The term query searches for exact matches of a term in the index and returns documents containing that term.
Execution Sample
Elasticsearch
{
  "query": {
    "term": { "status": { "value": "active" } }
  }
}
This query finds documents where the field 'status' exactly matches the term 'active'.
Execution Table
StepActionInput/ConditionResult/Output
1Receive query{"term": {"status": {"value": "active"}}}Query parsed
2Parse term queryField: status, Term: activeReady to search exact term
3Search indexLook for documents with status = 'active'Documents with exact match found
4Check matchesAre there documents with status 'active'?Yes, matches found
5Return resultsMatching documentsDocuments with status 'active' returned
💡 Execution stops after returning matching documents or empty if none found
Variable Tracker
VariableStartAfter Step 2After Step 3Final
querynull{"term": {"status": {"value": "active"}}}{"term": {"status": {"value": "active"}}}Same
fieldnullstatusstatusstatus
termnullactiveactiveactive
matches_foundnullnulltruetrue
resultsnullnullnullDocuments with status 'active'
Key Moments - 2 Insights
Why does the term query not find documents if the term case or format differs?
Because term query looks for exact matches (see execution_table step 3), it does not analyze or change the term. So 'Active' is different from 'active'.
What happens if the field does not exist in some documents?
Those documents are ignored because the term query only matches documents where the field exists with the exact term (execution_table step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the term being searched in step 2?
A"active"
B"status"
C"term"
D"query"
💡 Hint
Check the 'Input/Condition' column in step 2 of execution_table
At which step does the system confirm if matching documents exist?
AStep 1
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Action' column for checking matches in execution_table
If the term was changed to 'Active' (capital A), how would the results change?
ASame documents returned
BNo documents returned
CAll documents returned
DError occurs
💡 Hint
Recall that term query matches exact terms (see key_moments about case sensitivity)
Concept Snapshot
Term query syntax:
{
  "query": {
    "term": { "field": "value" }
  }
}

- Matches exact term in field
- Case sensitive and no analysis
- Returns documents with exact match
Full Transcript
The term query in Elasticsearch searches for documents containing an exact term in a specified field. It does not analyze or change the term, so the match must be exact including case. The process starts by receiving the query, parsing the term and field, searching the index for exact matches, checking if matches exist, and then returning the matching documents. If no matches are found, an empty result is returned. This query is useful when you want precise matching without text analysis.