Completion field in properties with type completion = {
"properties": {
"suggest": { "type": "completion" }
}
} [OK]
Hint: Completion field must be under properties with type 'completion' [OK]
Common Mistakes:
Placing completion field outside properties
Using text or keyword type instead of completion
Misnaming mapping keys
3. Given the following suggest query, what will be the expected output if the index contains documents with suggest fields 'apple', 'applet', and 'application'?
Assuming the mapping defines the completion field as suggest (not suggestion).
medium
A. The prefix value 'ban' is invalid
B. The suggest name 'my-suggest' is not allowed
C. The field name in completion should be 'suggest', not 'suggestion'
D. The suggest query must be inside 'query' key
Solution
Step 1: Check field name in completion suggester
The completion suggester must reference the correct field name defined in the mapping. Here, the mapping uses 'suggest', but the query uses 'suggestion'.
Step 2: Validate other parts of the query
The prefix 'ban' is valid, suggest name 'my-suggest' is allowed, and suggest queries do not require a 'query' key.
Final Answer:
The field name in completion should be 'suggest', not 'suggestion' -> Option C
Quick Check:
Field name mismatch causes error [OK]
Hint: Field name in query must match mapping exactly [OK]
Common Mistakes:
Using wrong field name in completion query
Thinking prefix value is invalid
Expecting suggest query inside 'query' key
5. You want to implement a completion suggester that suggests city names but excludes any suggestions that start with the letter 'x'. Which approach correctly applies this filter in the suggest query?
Step 1: Understand filtering with contexts in completion suggester
Completion suggester supports filtering using contexts. To exclude suggestions starting with 'x', you include all allowed first letters except 'x' in the context filter.
Step 2: Analyze each option
{
"suggest": {
"city-suggest": {
"prefix": "",
"completion": {
"field": "city_suggest",
"skip_duplicates": true
}
}
}
} has no filtering. {
"suggest": {
"city-suggest": {
"prefix": "",
"completion": {
"field": "city_suggest",
"contexts": {
"first_letter": ["!x"]
}
}
}
}
} tries to exclude 'x' with '!x' which is invalid syntax. {
"suggest": {
"city-suggest": {
"prefix": "",
"completion": {
"field": "city_suggest",
"contexts": {
"first_letter": ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "y", "z"]
}
}
}
}
} explicitly lists all letters except 'x' in contexts, correctly filtering out 'x'. {
"suggest": {
"city-suggest": {
"prefix": "",
"completion": {
"field": "city_suggest",
"filter": {
"term": { "first_letter": "x" }
}
}
}
}
} uses a 'filter' key which is not supported in completion suggester.