0
0
Elasticsearchquery~20 mins

Phrase suggestions (did you mean) in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Phrase Suggestion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Phrase Suggestion Output for Misspelled Query
Given the following Elasticsearch phrase suggestion query, what is the expected output suggestion for the misspelled word "appl"?
Elasticsearch
{
  "suggest": {
    "text": "appl",
    "simple_phrase": {
      "phrase": {
        "field": "title.trigram",
        "size": 1,
        "gram_size": 3,
        "direct_generator": [{
          "field": "title.trigram",
          "suggest_mode": "always"
        }],
        "highlight": {
          "pre_tag": "<em>",
          "post_tag": "</em>"
        }
      }
    }
  }
}
A{"simple_phrase":[{"text":"appl","highlighted":"<em>appl</em>"}]}
B{"simple_phrase":[{"text":"apply","highlighted":"<em>apply</em>"}]}
C{"simple_phrase":[{"text":"apple","highlighted":"<em>apple</em>"}]}
D{"simple_phrase":[]}
Attempts:
2 left
💡 Hint
Think about how phrase suggestions correct common misspellings using trigram analysis.
🧠 Conceptual
intermediate
1:30remaining
Understanding the Purpose of Direct Generator in Phrase Suggestions
What is the main role of the "direct_generator" in an Elasticsearch phrase suggestion query?
AIt highlights the matched terms in the search results.
BIt generates candidate corrections based on the specified field and suggest mode.
CIt controls the number of suggestions returned by the query.
DIt filters out suggestions that do not match the original query exactly.
Attempts:
2 left
💡 Hint
Consider how Elasticsearch finds possible corrections for misspelled words.
Predict Output
advanced
2:00remaining
Output of Phrase Suggestion with Multiple Candidates
What is the output of the following phrase suggestion query when the input text is "recieve" and the index contains "receive" and "recipe"?
Elasticsearch
{
  "suggest": {
    "text": "recieve",
    "phrase_suggester": {
      "phrase": {
        "field": "content.trigram",
        "size": 2,
        "gram_size": 3,
        "direct_generator": [{
          "field": "content.trigram",
          "suggest_mode": "always"
        }],
        "highlight": {
          "pre_tag": "<b>",
          "post_tag": "</b>"
        }
      }
    }
  }
}
A{"phrase_suggester":[{"text":"receive","highlighted":"<b>receive</b>"},{"text":"recipe","highlighted":"<b>recipe</b>"}]}
B{"phrase_suggester":[{"text":"recieve","highlighted":"<b>recieve</b>"}]}
C{"phrase_suggester":[{"text":"receipt","highlighted":"<b>receipt</b>"}]}
D{"phrase_suggester":[]}
Attempts:
2 left
💡 Hint
The suggester returns the top 2 candidates based on trigram similarity.
🔧 Debug
advanced
1:30remaining
Identify the Error in Phrase Suggestion Query
What error will this Elasticsearch phrase suggestion query produce?
Elasticsearch
{
  "suggest": {
    "text": "exampel",
    "phrase": {
      "field": "body.trigram",
      "gram_size": 3,
      "direct_generator": {
        "field": "body.trigram",
        "suggest_mode": "missing"
      }
    }
  }
}
ARuntimeError: suggest_mode 'missing' is invalid
BNo error, query runs successfully
CTypeError: field parameter missing in direct_generator
DSyntaxError: direct_generator must be an array, not an object
Attempts:
2 left
💡 Hint
Check the data type of direct_generator in the phrase suggestion syntax.
🧠 Conceptual
expert
2:00remaining
Why Use Phrase Suggestions Instead of Term Suggestions?
Why would you choose to use phrase suggestions (did you mean) over term suggestions in Elasticsearch?
APhrase suggestions consider the context of multiple words to correct phrases, reducing nonsensical corrections.
BPhrase suggestions are faster to compute than term suggestions.
CTerm suggestions do not support highlighting of corrections.
DPhrase suggestions only work on numeric fields, while term suggestions work on text.
Attempts:
2 left
💡 Hint
Think about how phrase suggestions handle multiple words compared to single words.