0
0
Elasticsearchquery~20 mins

Search-as-you-type field in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Search-as-you-type 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 Elasticsearch search-as-you-type query?
Given the following mapping and query, what will be the total number of hits returned?
Elasticsearch
{
  "mappings": {
    "properties": {
      "title": {
        "type": "search_as_you_type"
      }
    }
  }
}

POST /books/_search
{
  "query": {
    "match": {
      "title": {
        "query": "harry pot",
        "operator": "and"
      }
    }
  }
}
AThe query returns all documents containing both 'harry' and 'pot' in the title field.
BThe query returns documents containing the exact phrase 'harry pot' only.
CThe query returns documents containing either 'harry' or 'pot' in the title field.
DThe query returns no documents because 'pot' is incomplete.
Attempts:
2 left
💡 Hint
Consider how the 'operator': 'and' affects the match query with search_as_you_type fields.
🧠 Conceptual
intermediate
1:30remaining
Which Elasticsearch field type is best suited for implementing search-as-you-type functionality?
You want to enable users to get instant search suggestions as they type partial words. Which field type should you use in your mapping?
A"search_as_you_type"
B"keyword" with normalizer
C"text" with standard analyzer
D"completion"
Attempts:
2 left
💡 Hint
Think about which field type indexes prefixes of words for partial matching.
🔧 Debug
advanced
2:30remaining
Why does this search-as-you-type query return zero results?
Given this mapping and query, why does the search return no hits? Mapping: { "properties": { "name": { "type": "search_as_you_type" } } } Query: { "query": { "match": { "name": "j" } } }
AThe query is missing the 'operator': 'and' parameter.
BThe query string 'j' is too short to match any indexed prefix.
CThe 'match' query does not work with 'search_as_you_type' fields; a 'multi_match' is required.
DThe field 'name' is not analyzed, so partial matches fail.
Attempts:
2 left
💡 Hint
Consider the minimum prefix length indexed by default in 'search_as_you_type'.
📝 Syntax
advanced
2:00remaining
Which query syntax correctly searches a search_as_you_type field for partial input 'prog'?
Select the valid Elasticsearch query that searches the 'title' field of type 'search_as_you_type' for the prefix 'prog'.
A{ "match": { "title": "prog" } }
B{ "prefix": { "title": "prog" } }
C{ "match_phrase_prefix": { "title": "prog" } }
D{ "term": { "title": "prog" } }
Attempts:
2 left
💡 Hint
Which query type supports prefix matching on analyzed fields?
🚀 Application
expert
3:00remaining
How to optimize search-as-you-type for multi-word inputs with Elasticsearch?
You want to implement a search-as-you-type feature that handles multi-word inputs efficiently, such as 'data scie'. Which approach is best to achieve accurate prefix matching on each word?
AUse a single 'search_as_you_type' field and query it with 'match' on the full input string.
BUse multiple 'search_as_you_type' fields for each word and combine queries with 'bool' must clauses.
CUse a 'completion' field with prefix queries for each word separately.
DUse a 'search_as_you_type' field and query with 'multi_match' type 'bool_prefix' to match prefixes of multiple words.
Attempts:
2 left
💡 Hint
Consider which query type supports prefix matching on multiple words in a single field.