Challenge - 5 Problems
Search-as-you-type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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"
}
}
}
}Attempts:
2 left
💡 Hint
Consider how the 'operator': 'and' affects the match query with search_as_you_type fields.
✗ Incorrect
The 'search_as_you_type' field indexes prefixes of words, so partial terms like 'pot' match 'potter'. Using 'operator': 'and' requires both terms to be present in the document, but they can be partial matches.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about which field type indexes prefixes of words for partial matching.
✗ Incorrect
The 'search_as_you_type' field type is designed to index prefixes of words to support efficient search-as-you-type queries.
🔧 Debug
advanced2: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"
}
}
}
Attempts:
2 left
💡 Hint
Consider the minimum prefix length indexed by default in 'search_as_you_type'.
✗ Incorrect
By default, 'search_as_you_type' indexes prefixes starting from length 2, so a 1-letter query like 'j' does not match any prefix.
📝 Syntax
advanced2: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'.
Attempts:
2 left
💡 Hint
Which query type supports prefix matching on analyzed fields?
✗ Incorrect
The 'match_phrase_prefix' query supports prefix matching on analyzed fields like 'search_as_you_type'. 'prefix' query works only on keyword fields, and 'term' requires exact match.
🚀 Application
expert3: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?
Attempts:
2 left
💡 Hint
Consider which query type supports prefix matching on multiple words in a single field.
✗ Incorrect
The 'multi_match' query with type 'bool_prefix' is designed to efficiently match prefixes of multiple words in a 'search_as_you_type' field, improving multi-word search-as-you-type experience.