Bird
0
0

Why might this term query fail to find documents?

medium📝 Debug Q7 of 15
Elasticsearch - Basic Search Queries
Why might this term query fail to find documents?
{ "query": { "term": { "description": "Fast Car" } } }

Assuming description is a text field analyzed with the standard analyzer.
ABecause the field 'description' does not exist
BBecause term query does not analyze the input and 'Fast Car' is analyzed in the index
CBecause term query only works on numeric fields
DBecause the query syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Understand term query behavior on analyzed fields

    Term query matches exact terms without analysis.
  2. Step 2: Analyze the field type

    The description field is analyzed, so stored terms are tokenized and lowercased.
  3. Step 3: Reason about the query failure

    The query term 'Fast Car' is not analyzed, so it won't match tokenized terms like 'fast' and 'car'.
  4. Final Answer:

    Because term query does not analyze the input and 'Fast Car' is analyzed in the index -> Option B
  5. Quick Check:

    Term query requires exact term matching without analysis [OK]
Quick Trick: Term query does not analyze input; use keyword fields [OK]
Common Mistakes:
MISTAKES
  • Expecting term query to analyze input text
  • Using term query on analyzed text fields expecting full phrase match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes