Bird
Raised Fist0
Elasticsearchquery~20 mins

Match query in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Match 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 Match query?
Given the following Elasticsearch Match query, what documents will be matched if the index contains documents with the field title having values:
1. "Quick brown fox"
2. "Brown fox jumps"
3. "Lazy dog"

Query:
{"query": {"match": {"title": "brown fox"}}}
Elasticsearch
{"query": {"match": {"title": "brown fox"}}}
ADocuments 1 and 2 only
BDocuments 1, 2, and 3
CDocument 2 only
DDocument 3 only
Attempts:
2 left
💡 Hint
Match query analyzes the input text and looks for documents containing any of the terms after analysis.
🧠 Conceptual
intermediate
1:30remaining
How does the operator parameter affect a Match query?
In an Elasticsearch Match query, what is the effect of setting the operator parameter to and instead of the default or?
AThe query matches documents containing none of the terms
BThe query matches documents containing all the terms in the query string
CThe query matches documents containing any of the terms in the query string
DThe query matches documents only if the terms appear in the exact order
Attempts:
2 left
💡 Hint
Think about how 'and' changes the condition from 'any' to 'all'.
🔧 Debug
advanced
2:30remaining
Why does this Match query return no results?
Consider this Match query:
{"query": {"match": {"description": {"query": "fast runner", "operator": "and"}}}}

Given documents:
1. {"description": "fast and agile"}
2. {"description": "runner and jumper"}
3. {"description": "fast runner"}

Why does the query return only document 3?
ABecause the query string is treated as a phrase and only exact matches are returned
BBecause the query is missing a 'match_phrase' type
CBecause operator 'and' requires both 'fast' and 'runner' to be present in the same document
DBecause the field 'description' is not analyzed
Attempts:
2 left
💡 Hint
Check how the 'and' operator affects term matching in documents.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this Match query
Which option contains a syntax error in the Elasticsearch Match query?
A{"query": {"match": {"content": {"query": "quick fox", "operator": "or"}}}}
B{"query": {"match": {"content": {"query": "quick fox", "fuzziness": "AUTO"}}}}
C{"query": {"match": {"content": "quick fox"}}}
D{"query": {"match": {"content": {"query": "quick fox", "operator": or}}}}
Attempts:
2 left
💡 Hint
Check the quotes around string values in JSON.
🚀 Application
expert
3:00remaining
Which Match query option produces exactly 2 matched documents?
Given an index with documents:
1. {"text": "apple banana cherry"}
2. {"text": "banana cherry"}
3. {"text": "apple cherry"}
4. {"text": "banana apple"}

Which Match query will match exactly documents 1 and 3?
A{"query": {"match": {"text": {"query": "apple cherry", "operator": "and"}}}}
B{"query": {"match": {"text": {"query": "banana cherry", "operator": "and"}}}}
C{"query": {"match": {"text": {"query": "apple banana", "operator": "or"}}}}
D{"query": {"match": {"text": {"query": "apple", "operator": "and"}}}}
Attempts:
2 left
💡 Hint
Look for documents containing both 'apple' and 'cherry'.

Practice

(1/5)
1. What does the match query in Elasticsearch primarily do?
easy
A. Updates documents with new values
B. Finds documents with text similar to the search words
C. Deletes documents matching the query
D. Creates a new index for the documents

Solution

  1. Step 1: Understand the purpose of match query

    The match query is designed to find documents that contain text similar to the search words provided.
  2. Step 2: Differentiate from other operations

    Deleting, updating, or creating indexes are not functions of the match query; it only searches text.
  3. Final Answer:

    Finds documents with text similar to the search words -> Option B
  4. Quick Check:

    Match query = text search [OK]
Hint: Match query searches text similarity, not modify data [OK]
Common Mistakes:
  • Confusing match query with delete or update operations
  • Thinking match query creates indexes
  • Assuming match query returns exact matches only
2. Which of the following is the correct syntax for a basic match query in Elasticsearch?
easy
A. { "match": { "field": "search text" } }
B. { "match": "field": "search text" }
C. { "match": { "field" = "search text" } }
D. { "match": [ "field", "search text" ] }

Solution

  1. Step 1: Review correct JSON structure for match query

    The match query requires a JSON object with the field name as key and the search text as value inside another object.
  2. Step 2: Identify syntax errors in options

    { "match": { "field": "search text" } } uses correct JSON with colon separators and nested object. Options A, B, and C have syntax errors like missing braces, wrong assignment, or array usage.
  3. Final Answer:

    { "match": { "field": "search text" } } -> Option A
  4. Quick Check:

    Correct JSON syntax = { "match": { "field": "search text" } } [OK]
Hint: Match query uses nested JSON with field: text inside match [OK]
Common Mistakes:
  • Using equal sign instead of colon
  • Missing curly braces around field and text
  • Using array instead of object for field and text
3. Given this Elasticsearch query:
{ "query": { "match": { "title": { "query": "quick brown fox", "operator": "and" } } } }

What does the operator": "and" do in this match query?
medium
A. Returns documents containing all the words 'quick', 'brown', and 'fox'
B. Returns documents containing any of the words 'quick', 'brown', or 'fox'
C. Returns documents containing the exact phrase 'quick brown fox'
D. Returns documents containing none of the words

Solution

  1. Step 1: Understand the operator option in match query

    The operator 'and' means all words in the query must be present in the document for a match.
  2. Step 2: Compare with other operators

    Operator 'or' would return documents with any word, but 'and' requires all words.
  3. Final Answer:

    Returns documents containing all the words 'quick', 'brown', and 'fox' -> Option A
  4. Quick Check:

    Operator 'and' = all words required [OK]
Hint: Operator 'and' means all words must appear [OK]
Common Mistakes:
  • Confusing 'and' with 'or' operator
  • Thinking 'and' means exact phrase match
  • Ignoring operator option defaults
4. Identify the error in this match query:
{ "query": { "match": { "content": { "query": "data science", "operator": "AND" } } } }
medium
A. The field name 'content' is invalid
B. The query string must be an array, not a string
C. The operator value should be lowercase 'and', not uppercase 'AND'
D. The match query cannot have an operator option

Solution

  1. Step 1: Check operator value case sensitivity

    Elasticsearch expects the operator value to be lowercase 'and' or 'or'. Uppercase 'AND' is invalid.
  2. Step 2: Validate other parts of the query

    The field name 'content' is valid, query string can be a string, and match query supports operator option.
  3. Final Answer:

    The operator value should be lowercase 'and', not uppercase 'AND' -> Option C
  4. Quick Check:

    Operator values are lowercase [OK]
Hint: Operator values must be lowercase 'and' or 'or' [OK]
Common Mistakes:
  • Using uppercase 'AND' or 'OR' for operator
  • Assuming query must be an array
  • Thinking operator option is not allowed
5. You want to find documents where the description field contains either the word 'fast' or 'quick', but not necessarily both. Which match query is correct?
hard
A. { "match": { "description": { "query": "fast quick", "operator": "not" } } }
B. { "match": { "description": { "query": "fast quick", "operator": "and" } } }
C. { "match": { "description": "fast OR quick" } }
D. { "match": { "description": { "query": "fast quick", "operator": "or" } } }

Solution

  1. Step 1: Understand the operator 'or' in match query

    Operator 'or' returns documents containing any of the words, so either 'fast' or 'quick' or both.
  2. Step 2: Evaluate other options

    B requires both words, C searches for documents containing 'fast', 'OR', and 'quick' (treating OR as literal text), D uses invalid operator 'not'.
  3. Final Answer:

    { "match": { "description": { "query": "fast quick", "operator": "or" } } } -> Option D
  4. Quick Check:

    Use operator 'or' for any word match [OK]
Hint: Use operator 'or' to match any word in query [OK]
Common Mistakes:
  • Using 'and' when 'or' is needed
  • Using 'OR' in the search text instead of operator
  • Using invalid operator like 'not'
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