Bird
Raised Fist0
Elasticsearchquery~20 mins

Autocomplete with edge n-gram in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Edge N-Gram 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 edge n-gram tokenizer example?
Given the following Elasticsearch analyzer configuration using edge n-gram tokenizer, what tokens will be generated for the input text "search"?
Elasticsearch
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "edge_ngram_tokenizer": {
          "type": "edge_ngram",
          "min_gram": 2,
          "max_gram": 4,
          "token_chars": ["letter"]
        }
      },
      "analyzer": {
        "edge_ngram_analyzer": {
          "tokenizer": "edge_ngram_tokenizer"
        }
      }
    }
  }
}
A["se", "sea", "sear"]
B["se", "sea", "sear", "searc", "search"]
C["se", "sea", "sear", "ea", "ear", "earc", "ar", "arc", "arch", "rc", "rch", "ch"]
D["s", "se", "sea", "sear"]
Attempts:
2 left
💡 Hint
Edge n-gram tokenizer generates tokens starting from the beginning of the word with lengths between min_gram and max_gram.
🧠 Conceptual
intermediate
1:30remaining
Which option best describes the purpose of edge n-gram tokenizer in autocomplete?
What is the main reason to use an edge n-gram tokenizer in an autocomplete feature?
ATo remove stop words and reduce index size.
BTo split text into sentences for better indexing.
CTo generate tokens from the middle of words to improve search accuracy.
DTo generate tokens starting from the beginning of words to match prefixes quickly.
Attempts:
2 left
💡 Hint
Think about how autocomplete suggests words as you type from the start.
🔧 Debug
advanced
2:00remaining
Why does this edge n-gram analyzer not produce any tokens?
Given this analyzer configuration, why does the input text "hello" produce no tokens?
Elasticsearch
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "my_edge_ngram": {
          "type": "edge_ngram",
          "min_gram": 3,
          "max_gram": 5,
          "token_chars": ["digit"]
        }
      },
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "my_edge_ngram"
        }
      }
    }
  }
}
ABecause the min_gram is larger than the input length.
BBecause the tokenizer type is invalid.
CBecause token_chars is set to 'digit' but input contains only letters.
DBecause max_gram is less than min_gram.
Attempts:
2 left
💡 Hint
Check the token_chars setting and the input text characters.
📝 Syntax
advanced
1:30remaining
Which option correctly defines an edge n-gram tokenizer with min_gram 1 and max_gram 3?
Select the valid Elasticsearch tokenizer configuration for edge n-gram with min_gram 1 and max_gram 3.
A{ "type": "edgeNGram", "minGram": 1, "maxGram": 3 }
B{ "type": "edge_ngram", "min_gram": 1, "max_gram": 3 }
C{ "type": "edge_ngram", "minGram": 1, "maxGram": 3 }
D{ "type": "edge_ngram", "min_gram": "1", "max_gram": "3" }
Attempts:
2 left
💡 Hint
Check the correct property names and value types for edge n-gram tokenizer.
🚀 Application
expert
2:00remaining
How many tokens are generated by this edge n-gram tokenizer for input 'data'?
Given this tokenizer configuration, how many tokens will be generated for the input text "data"?
{
  "type": "edge_ngram",
  "min_gram": 1,
  "max_gram": 3,
  "token_chars": ["letter"]
}
A3
B4
C2
D1
Attempts:
2 left
💡 Hint
Count tokens starting from the first letter with lengths 1 to 3.

Practice

(1/5)
1. What is the main purpose of using an edge_ngram tokenizer in Elasticsearch autocomplete?
easy
A. To break words into prefixes for fast autocomplete suggestions
B. To sort search results alphabetically
C. To remove stop words from the search query
D. To index only complete words without partial matches

Solution

  1. Step 1: Understand edge n-gram tokenizer function

    The edge n-gram tokenizer splits words into prefixes, like 'app', 'appl', 'apple' for 'apple'.
  2. Step 2: Relate tokenizer to autocomplete

    This prefix splitting allows Elasticsearch to quickly suggest words as users type partial input.
  3. Final Answer:

    To break words into prefixes for fast autocomplete suggestions -> Option A
  4. Quick Check:

    edge_ngram tokenizer = prefix splitting [OK]
Hint: Edge n-gram creates prefixes for autocomplete speed [OK]
Common Mistakes:
  • Thinking edge n-gram sorts results
  • Confusing with stop word removal
  • Assuming it indexes only full words
2. Which of the following is the correct way to define an edge_ngram tokenizer in Elasticsearch settings?
easy
A. { "tokenizer": { "my_edge_ngram": { "type": "edge_ngram", "min_gram": 2, "max_gram": 5, "token_chars": ["letter"] } } }
B. { "tokenizer": { "my_edge_ngram": { "type": "standard", "min_gram": 2, "max_gram": 5 } } }
C. { "analyzer": { "my_edge_ngram": { "type": "edge_ngram" } } }
D. { "tokenizer": { "my_edge_ngram": { "type": "ngram", "min_gram": 1, "max_gram": 3 } } }

Solution

  1. Step 1: Identify correct tokenizer type and parameters

    The edge_ngram tokenizer requires type 'edge_ngram' with min_gram and max_gram settings.
  2. Step 2: Check token_chars usage

    { "tokenizer": { "my_edge_ngram": { "type": "edge_ngram", "min_gram": 2, "max_gram": 5, "token_chars": ["letter"] } } } correctly sets token_chars to 'letter' to include only letters in tokens.
  3. Final Answer:

    Option A with type 'edge_ngram' and proper min_gram, max_gram -> Option A
  4. Quick Check:

    edge_ngram tokenizer syntax = { "tokenizer": { "my_edge_ngram": { "type": "edge_ngram", "min_gram": 2, "max_gram": 5, "token_chars": ["letter"] } } } [OK]
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

  1. 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.
  2. Step 2: Generate tokens for 'cat'

    Tokens are 'c' (1 letter), 'ca' (2 letters), and 'cat' (3 letters).
  3. Final Answer:

    ["c", "ca", "cat"] -> Option D
  4. 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

  1. Step 1: Understand analyzer and search_analyzer roles

    Indexing uses edge n-gram tokenizer, but searching uses standard analyzer which does not generate prefixes.
  2. 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.
  3. Final Answer:

    Search analyzer should match or complement edge n-gram analyzer, not standard -> Option B
  4. 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

  1. Step 1: Understand indexing with edge n-gram tokenizer

    Indexing uses edge n-gram tokenizer to create prefix tokens for autocomplete.
  2. 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.
  3. 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.
  4. Final Answer:

    Index with edge n-gram, search with standard + lowercase analyzer -> Option C
  5. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard