What is the purpose of using edge n-gram in autocomplete?
Edge n-gram helps break down words into smaller parts starting from the beginning, allowing fast prefix matching for autocomplete suggestions.
Click to reveal answer
beginner
Which Elasticsearch analyzer is commonly used to create edge n-grams?
The edge_ngram tokenizer or filter is used within a custom analyzer to generate edge n-grams for autocomplete.
Click to reveal answer
intermediate
What is the difference between min_gram and max_gram in edge n-gram settings?
min_gram sets the smallest size of the n-gram, and max_gram sets the largest size. For example, min_gram=2 and max_gram=5 generate n-grams of length 2 to 5.
Click to reveal answer
intermediate
Why should edge n-gram be applied at index time and not at search time?
Applying edge n-gram at index time creates tokens for fast prefix matching. At search time, using a standard analyzer keeps queries simple and efficient.
Click to reveal answer
advanced
Give an example of a simple Elasticsearch mapping using edge n-gram for autocomplete.
A mapping with a custom analyzer using edge n-gram filter on a text field enables autocomplete. Example:
Hint: Look for type 'edge_ngram' with min_gram and max_gram [OK]
Common Mistakes:
Using 'standard' type instead of 'edge_ngram'
Defining edge_ngram under analyzer instead of tokenizer
Confusing ngram with edge_ngram tokenizer
3. Given this analyzer configuration using edge n-gram tokenizer:
{ "settings": { "analysis": { "tokenizer": { "autocomplete_tokenizer": { "type": "edge_ngram", "min_gram": 1, "max_gram": 3, "token_chars": ["letter"] } }, "analyzer": { "autocomplete": { "type": "custom", "tokenizer": "autocomplete_tokenizer", "filter": ["lowercase"] } } } }}
What tokens will be generated for the word "cat" during indexing?
medium
A. ["cat"]
B. ["c", "a", "t"]
C. ["ca", "cat", "cat"]
D. ["c", "ca", "cat"]
Solution
Step 1: Understand edge n-gram tokenizer with min_gram=1 and max_gram=3
It creates tokens from the start of the word with lengths 1 to 3 letters.
Step 2: Generate tokens for 'cat'
Tokens are 'c' (1 letter), 'ca' (2 letters), and 'cat' (3 letters).
Final Answer:
["c", "ca", "cat"] -> Option D
Quick Check:
edge n-gram tokens for 'cat' = ["c", "ca", "cat"] [OK]
Hint: Edge n-gram tokens start from first letter up to max_gram [OK]
Common Mistakes:
Assuming only full word token is generated
Including tokens from middle or end of word
Confusing n-gram with edge n-gram tokens
4. You have this analyzer configuration for autocomplete but your search results do not return expected matches:
{ "settings": { "analysis": { "tokenizer": { "autocomplete_tokenizer": { "type": "edge_ngram", "min_gram": 2, "max_gram": 5 } }, "analyzer": { "autocomplete": { "type": "custom", "tokenizer": "autocomplete_tokenizer", "filter": ["lowercase"] }, "search_analyzer": { "type": "standard" } } } }}
What is the likely cause of the problem?
medium
A. The tokenizer type should be 'ngram' not 'edge_ngram'
B. The search analyzer is incorrectly defined as 'standard' instead of using the same analyzer
C. The min_gram value is too low causing too many tokens
D. The filter 'lowercase' should not be used in the analyzer
Solution
Step 1: Understand analyzer and search_analyzer roles
Indexing uses edge n-gram tokenizer, but searching uses standard analyzer which does not generate prefixes.
Step 2: Identify mismatch causing no autocomplete matches
Because search analyzer does not tokenize input into prefixes, queries won't match edge n-gram tokens.
Final Answer:
Search analyzer should match or complement edge n-gram analyzer, not standard -> Option B
Quick Check:
Analyzer mismatch = The search analyzer is incorrectly defined as 'standard' instead of using the same analyzer [OK]
Hint: Search analyzer must complement edge n-gram tokenizer [OK]
Common Mistakes:
Changing min_gram instead of fixing analyzer mismatch
Confusing ngram and edge_ngram tokenizer types
Removing lowercase filter unnecessarily
5. You want to implement autocomplete for a product search using edge n-gram tokenizer. Which approach correctly combines indexing and searching analyzers for best autocomplete results?
hard
A. Use edge n-gram tokenizer in the indexing analyzer and standard analyzer in the search analyzer
B. Use edge n-gram tokenizer in both indexing and search analyzers
C. Use edge n-gram tokenizer in indexing analyzer and a lowercase + standard tokenizer in search analyzer
D. Use standard tokenizer in indexing analyzer and edge n-gram tokenizer in search analyzer
Solution
Step 1: Understand indexing with edge n-gram tokenizer
Indexing uses edge n-gram tokenizer to create prefix tokens for autocomplete.
Step 2: Understand searching with standard tokenizer plus lowercase filter
Search analyzer uses standard tokenizer to tokenize user input normally and lowercase filter to match indexed tokens.
Step 3: Why not use edge n-gram tokenizer in search analyzer?
Using edge n-gram in search analyzer can cause unexpected partial matches and performance issues.
Final Answer:
Index with edge n-gram, search with standard + lowercase analyzer -> Option C
Quick Check:
Index edge n-gram + search standard = Use edge n-gram tokenizer in indexing analyzer and a lowercase + standard tokenizer in search analyzer [OK]
Hint: Index with edge n-gram, search with standard + lowercase [OK]
Common Mistakes:
Using edge n-gram tokenizer in search analyzer
Using standard tokenizer in indexing analyzer
Not applying lowercase filter in search analyzer
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.