如果我要搜索完整字符串Knasweg 12, 9062 Knasweg, Österreich
,如何突出显示(并返回)仅限于子字符串Knasweg
?
换句话说,我想查询以下内容:
GET _search
{
"query": {
"match": {
"location.pretty_address": {
"query": "Knasweg",
"operator": "and",
"fuzziness": 1
}
}
},
"highlight": {
"pre_tags": "",
"post_tags": "",
"fields": {
"location.pretty_address": {
"highlight_query": {
"bool": {
"must": {
"match": {
"location.pretty_address": {
"query": "Knasweg"
}
}
}
}
}
}
}
}
}
返回
"highlight": {
"location.pretty_address": [
"Knasweg"
]
}
替代
"highlight": {
"location.pretty_address": [
"Knasweg 12, 9062 Knasweg, Österreich"
]
}
我的映射:
"location": {
"dynamic": "true",
"properties": {
"pretty_address": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"analyzer": "autocomplete_analyzer"
}
}
我的设置:
"settings": {
"index": {
"analysis": {
"analyzer": {
"comma_analyzer": {
"tokenizer": "comma_tokenizer"
},
"autocomplete_analyzer": {
"filter": "lowercase",
"tokenizer": "autocomplete_tokenizer"
}
},
"tokenizer": {
"autocomplete_tokenizer": {
"type": "ngram",
"min_gram": "3",
"max_gram": "20"
},
"comma_tokenizer": {
"pattern": ", ",
"type": "pattern"
}
}
}
}
}