Bird
Raised Fist0
Elasticsearchquery~20 mins

Term query in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Term Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this term query?
Given the following Elasticsearch term query, what documents will it match?
Elasticsearch
{
  "query": {
    "term": {
      "status": {
        "value": "active"
      }
    }
  }
}
ADocuments where the field 'status' exactly matches the string 'active'
BDocuments where the field 'status' starts with 'active'
CDocuments where the field 'status' contains the word 'active' anywhere in the text
DDocuments where the field 'status' is missing or null
Attempts:
2 left
💡 Hint
Remember, term query matches exact values without analyzing the text.
🧠 Conceptual
intermediate
1:30remaining
Which field type is best for term query?
Which Elasticsearch field type is most suitable for using with a term query to match exact values?
Akeyword (not analyzed string field)
Btext (analyzed string field)
Cdate
Dgeo_point
Attempts:
2 left
💡 Hint
Term query works best on fields that are not broken into tokens.
🔧 Debug
advanced
2:30remaining
Why does this term query return no results?
You run this term query but get no results. What is the likely cause?
Elasticsearch
{
  "query": {
    "term": {
      "user": "John Doe"
    }
  }
}
AThe term query only works on numeric fields
BThe term query syntax is invalid and causes a syntax error
CThe field 'user' does not exist in the index
DThe field 'user' is analyzed and the term query expects exact match, so 'John Doe' does not match the analyzed tokens
Attempts:
2 left
💡 Hint
Think about how term query matches exact values and how analyzed fields store data.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this term query
Which option contains a syntax error in the term query?
A{ "query": { "term": { "status": "active" } } }
B{ "query": { "term": { "status": ["active"] } } }
C{ "query": { "term": { "status": { "value": "active", "boost": 2.0 } } } }
D{ "query": { "term": { "status": { "value": "active" } } } }
Attempts:
2 left
💡 Hint
Check the expected data type for the term query value.
🚀 Application
expert
3:00remaining
How many documents match this term query?
Assume an Elasticsearch index has these documents with field 'category': 1. {"category": "Books"} 2. {"category": "books"} 3. {"category": "Books and More"} 4. {"category": "Books"} Given the term query below, how many documents will match?
Elasticsearch
{
  "query": {
    "term": {
      "category.keyword": "Books"
    }
  }
}
A1
B3
C2
D4
Attempts:
2 left
💡 Hint
Term query on keyword fields is case sensitive and matches exact values only.

Practice

(1/5)
1. What does a term query in Elasticsearch do?
easy
A. Analyzes and breaks the search term into tokens
B. Finds exact matches of the given term in the data
C. Finds documents with terms similar to the search term
D. Sorts documents based on the term frequency

Solution

  1. Step 1: Understand the purpose of term query

    A term query searches for exact matches without analyzing the search term.
  2. Step 2: Compare options with term query behavior

    Only Finds exact matches of the given term in the data describes exact matching, which is the core of term query.
  3. Final Answer:

    Finds exact matches of the given term in the data -> Option B
  4. Quick Check:

    Term query = exact match [OK]
Hint: Term query matches exactly, no analysis or tokenizing [OK]
Common Mistakes:
  • Confusing term query with match query that analyzes text
  • Thinking term query sorts results
  • Assuming term query finds similar or partial matches
2. Which of the following is the correct syntax for a term query in Elasticsearch?
easy
A. { "terms": { "user": ["kimchy"] } }
B. { "match": { "user": "kimchy" } }
C. { "term_query": { "user": "kimchy" } }
D. { "term": { "user": "kimchy" } }

Solution

  1. Step 1: Identify correct term query syntax

    The term query uses the key "term" with a field and exact value.
  2. Step 2: Check each option

    { "term": { "user": "kimchy" } } matches the correct syntax. { "match": { "user": "kimchy" } } is a match query, C is invalid, D is a terms query (plural) for multiple values.
  3. Final Answer:

    { "term": { "user": "kimchy" } } -> Option D
  4. Quick Check:

    Term query syntax = { "term": { "user": "kimchy" } } [OK]
Hint: Term query uses "term" key with field and exact value [OK]
Common Mistakes:
  • Using "match" instead of "term" for exact match
  • Confusing "term" with "terms" for single value
  • Adding extra keys like "term_query" which is invalid
3. Given this Elasticsearch query:
{ "query": { "term": { "status": "active" } } }

What documents will this query return?
medium
A. Documents where the status field exactly equals "active"
B. Documents where the status field contains the word "active" anywhere
C. Documents where the status field starts with "active"
D. Documents where the status field is analyzed and matches "active"

Solution

  1. Step 1: Understand term query behavior on field

    The term query matches documents where the field value exactly equals the given term without analysis.
  2. Step 2: Analyze each option

    Only Documents where the status field exactly equals "active" correctly describes exact equality. Others describe partial or analyzed matches which term query does not do.
  3. Final Answer:

    Documents where the status field exactly equals "active" -> Option A
  4. Quick Check:

    Term query = exact field value match [OK]
Hint: Term query matches exact field value only [OK]
Common Mistakes:
  • Thinking term query matches partial or analyzed text
  • Assuming term query matches prefixes or substrings
  • Confusing term query with match query behavior
4. You wrote this term query but it returns no results:
{ "query": { "term": { "user": "Kimchy" } } }

Your data has the user field stored as lowercase "kimchy". What is the problem?
medium
A. Term query is case sensitive and "Kimchy" does not match "kimchy"
B. The term query syntax is incorrect
C. The user field is missing in the documents
D. Term query analyzes the term and changes case

Solution

  1. Step 1: Understand term query case sensitivity

    Term query matches exact terms and is case sensitive, so "Kimchy" does not match "kimchy".
  2. Step 2: Check other options

    Syntax is correct, field exists, and term query does not analyze or change case.
  3. Final Answer:

    Term query is case sensitive and "Kimchy" does not match "kimchy" -> Option A
  4. Quick Check:

    Term query = exact case match [OK]
Hint: Term query matches exact case; check letter casing [OK]
Common Mistakes:
  • Assuming term query ignores case
  • Thinking syntax error causes no results
  • Believing term query analyzes or lowercases terms
5. You want to find documents where the tags field contains exactly the term urgent. The tags field is an array of keywords. Which query is best to use?
hard
A. { "match": { "tags": "urgent" } }
B. { "terms": { "tags": "urgent" } }
C. { "term": { "tags": "urgent" } }
D. { "term": { "tags.keyword": "urgent" } }

Solution

  1. Step 1: Understand term query on array fields

    Term query matches exact terms in arrays, so it works directly on the tags field.
  2. Step 2: Evaluate other options

    Match query analyzes text (not exact). Terms query expects multiple values to match any. Using tags.keyword is unnecessary if tags is keyword type.
  3. Final Answer:

    { "term": { "tags": "urgent" } } -> Option C
  4. Quick Check:

    Term query matches exact term in array [OK]
Hint: Use term query for exact keyword in array fields [OK]
Common Mistakes:
  • Using match query which analyzes and may not match exactly
  • Using terms query incorrectly for single term
  • Confusing field type and using .keyword unnecessarily
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