Complete the code to define a search-as-you-type field in the mapping.
{
"mappings": {
"properties": {
"title": {
"type": "[1]"
}
}
}
}The search_as_you_type type enables efficient search-as-you-type functionality in Elasticsearch.
Complete the code to add a subfield for exact matching inside the search-as-you-type field.
{
"mappings": {
"properties": {
"title": {
"type": "search_as_you_type",
"fields": {
"[1]": {
"type": "keyword"
}
}
}
}
}
}The subfield raw is commonly used for exact matching with the keyword type.
Fix the error in the query to search the search-as-you-type field for the prefix 'elastic'.
{
"query": {
"prefix": {
"title.[1]": "elastic"
}
}
}To search prefixes on the exact subfield, use the subfield name like raw.
Fill both blanks to complete the mapping with a search-as-you-type field and a subfield for exact matches.
{
"mappings": {
"properties": {
"name": {
"type": "[1]",
"fields": {
"[2]": {
"type": "keyword"
}
}
}
}
}
}The main field uses search_as_you_type and the subfield raw is for exact keyword matches.
Fill all three blanks to write a query that searches the search-as-you-type field for 'search' and sorts by the exact subfield.
{
"query": {
"match": {
"title.[1]": "search"
}
},
"sort": [
{
"title.[2]": {
"order": "[3]"
}
}
]
}The match query targets the main text field, sorting uses the raw subfield with ascending order.