在使用完整数据搜索字段时,我发现了突出显示的问题。我使用了自定义分析器,每个字段都存储为文本和关键字。
我使用空白作为搜索分析器。
我的自定义分析器是:
"analysis": {
"filter": {
"indexFilter": {
"type": "pattern_capture",
"preserve_original": "true",
"patterns": [
"([@,$,%,&,!,.,#,^,*]+)",
"([\\w,.]+)",
"([\\w,@]+)",
"([-]+)",
"(\\w+)"
]
}
},
"analyzer": {
"indexAnalyzer": {
"filter": [
"indexFilter",
"lowercase"
],
"tokenizer": "whitespace"
},
"searchAnalyzer": {
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
我的映射文件是:
"field": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "indexAnalyzer",
"search_analyzer": "searchAnalyzer"
}
我的问题是:
{
"from": 0,
"size": 24,
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "monkey business",
"type": "phrase",
"slop": "2",
"fields": []
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "unified",
"fields": {
"*": {}
}
}
}
我的亮点是:
"highlight": {
"field.keyword": [
"<em>monkey business</em>"
],
"field": [
"<em>monkey</em> <em>business</em>"
]
}