三种语法高亮方式
参照B站课程写的
1. plain highlight:默认方式,底层lucene highlight
get /mail/_search
{
"query": {
"match": {
"receiver": "陈一"
}
},
"highlight": {
"fields": {
"receiver": {}
}
}
}
查询结果最后会有 em
标记
"highlight": {
"receiver": [
"\"<em>陈一</em>清\" <ds.zhhsl@cn.gree.com>"
]
}
2. posting highlight:设置索引的 index_option=offset
优点
- 性能比plain highlight高,因为不需要重新对高亮文本进行分词
- 对磁盘的消耗少
- 将文本切割为句子,并对句子进行高亮,效果更好
索引建立示例
put /mail
{
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "standard_multilanguage",
"index_options": "offsets"
}
}
}
}
查询高亮语法与plain highlight一样,只是性能、效果略好
3. fast vector highlight
优点
- 对大field(大于1mb)性能更高
索引建立示例
put /mail
{
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "standard_multilanguage",
"term_vector": "with_positions_offsets"
}
}
}
}
查询高亮语法与plain highlight一样
强制使用某种高亮方式
get /mail/_search
{
"query": {
"match": {
"receiver": "陈一"
}
},
"highlight": {
"fields": {
"receiver": {
"type":"plain"
}
}
}
}