A wildcard query searches for terms that match a pattern with special characters like * (matches any number of characters) and ? (matches a single character). It helps find words with unknown parts.
Click to reveal answer
beginner
How does a prefix query work in Elasticsearch?
A prefix query finds documents where a field's value starts with a specified string. It is like searching for all words beginning with a certain prefix.
Click to reveal answer
beginner
Which wildcard characters are used in Elasticsearch wildcard queries?
The two main wildcard characters are * which matches zero or more characters, and ? which matches exactly one character.
Click to reveal answer
intermediate
What is a key difference between wildcard and prefix queries?
Wildcard queries allow patterns anywhere in the word using * and ?, while prefix queries only match the beginning of a word with a fixed string.
Click to reveal answer
intermediate
Why should wildcard queries be used carefully in Elasticsearch?
Wildcard queries can be slow and resource-heavy because they scan many terms. Using them on large datasets or with leading wildcards (like *abc) can hurt performance.
Click to reveal answer
Which wildcard character matches exactly one character in Elasticsearch?
A?
B*
C#
D%
✗ Incorrect
The ? character matches exactly one character, while * matches zero or more characters.
What does a prefix query in Elasticsearch do?
AMatches words starting with a string
BMatches words ending with a string
CMatches exact words only
DMatches any part of a word
✗ Incorrect
Prefix queries find words that start with the given string.
Which query is generally faster on large datasets?
AWildcard query with leading *
BWildcard query with trailing *
CPrefix query
DWildcard query with multiple ?
✗ Incorrect
Prefix queries are faster because they only match the start of terms, while wildcard queries can scan many terms.
Which wildcard query pattern is considered bad for performance?
Aabc*
B*abc
Cabc?def
Da?c*
✗ Incorrect
Leading wildcards like *abc cause Elasticsearch to scan many terms, slowing down the search.
In Elasticsearch, which query would you use to find all documents where a field starts with 'pre'?
AWildcard query with pattern 'pre*'
BTerm query with value 'pre'
CWildcard query with pattern '*pre'
DPrefix query with value 'pre'
✗ Incorrect
Prefix query with value 'pre' efficiently finds all terms starting with 'pre'.
Explain how wildcard and prefix queries differ in Elasticsearch and when you might use each.
Think about how flexible the search pattern is and performance.
You got /4 concepts.
Describe the performance considerations when using wildcard queries in Elasticsearch.
Consider how Elasticsearch searches terms internally.
You got /4 concepts.
Practice
(1/5)
1. What does a wildcard query with * symbol do in Elasticsearch?
easy
A. Matches terms ending with a specific suffix
B. Matches only the exact search term
C. Matches terms starting with a specific prefix
D. Matches any sequence of characters in the search term
Solution
Step 1: Understand the wildcard symbol *
The * symbol in wildcard queries matches zero or more characters in any position of the term.
Step 2: Compare with other options
Exact match requires no wildcard, prefix queries use a different query type, and suffix matching is not directly done by * alone.
Final Answer:
Matches any sequence of characters in the search term -> Option D
Quick Check:
wildcard * = match any chars [OK]
Hint: Remember * matches any characters, ? matches one character [OK]
Common Mistakes:
Confusing wildcard * with prefix query
Thinking * matches only one character
Assuming wildcard matches exact terms only
2. Which of the following is the correct syntax for a prefix query in Elasticsearch?
easy
A. { "prefix": { "field_name": "pre" } }
B. { "wildcard": { "field_name": "pre*" } }
C. { "match": { "field_name": "pre*" } }
D. { "term": { "field_name": "pre*" } }
Solution
Step 1: Identify prefix query syntax
Prefix queries use the prefix keyword with the field and the prefix string.
Step 2: Check other options
Wildcard queries use wildcard, match and term queries do not support prefix syntax with asterisk.
Final Answer:
{ "prefix": { "field_name": "pre" } } -> Option A
Quick Check:
prefix query uses "prefix" keyword [OK]
Hint: Prefix queries use "prefix" keyword, not wildcard or match [OK]
Common Mistakes:
Using wildcard syntax for prefix query
Using match query with asterisk
Confusing term query with prefix query
3. Given the following wildcard query, which documents will match?
{ "query": { "wildcard": { "name": "jo?n*" } } }
Assuming documents have names: "john", "joan", "jonas", "joanathan", "jo".
medium
A. ["joan", "jonas", "joanathan"]
B. ["john", "joan", "jo"]
C. ["john", "joan", "joanathan"]
D. ["john", "joan", "jonas", "joanathan", "jo"]
Solution
Step 1: Analyze the wildcard pattern "jo?n*"
The pattern means: 'jo' followed by any single character (due to '?'), then 'n', then any characters (due to '*').
Step 2: Check each name against the pattern
"john" matches ('h' replaces '?'), "joan" matches ('a' replaces '?'), "joanathan" matches ('a' replaces '?'). "jonas" does not match ('n' replaces '?' but next 'a' ≠ 'n'). "jo" is too short to match.
Final Answer:
["john", "joan", "joanathan"] -> Option C
Quick Check:
wildcard ? = one char, * = any chars [OK]
Hint: ? matches one char, * matches zero or more chars [OK]
Common Mistakes:
Assuming ? matches zero characters
Including too short strings like "jo"
Confusing wildcard with prefix query
4. You wrote this prefix query but it returns no results:
{ "query": { "prefix": { "title": "prog*" } } }
What is the error?
medium
A. Field name "title" is invalid
B. Prefix query should not include the asterisk (*)
C. Prefix queries require wildcard keyword
D. Prefix query must use match instead of prefix
Solution
Step 1: Understand prefix query syntax
Prefix queries expect a string prefix without wildcards like '*'. The asterisk is not needed and causes no matches.
Step 2: Check other options
Field name is assumed valid, wildcard keyword is different query type, and match query is unrelated to prefix syntax.
Final Answer:
Prefix query should not include the asterisk (*) -> Option B
Quick Check:
Prefix query uses plain prefix string, no * [OK]
Hint: Remove * from prefix query string to fix [OK]
Common Mistakes:
Including * in prefix query string
Confusing prefix with wildcard query
Using match query instead of prefix
5. You want to find all documents where the "username" field starts with "alex" but also want to allow any characters after "alex" including none. Which query is best and why?