总的来说:三种高亮显示
一、plain highlight(默认)
二、posting highlight(性能)
对磁盘的消耗更少
将文本切割为句子,并且对句子进行高亮,效果更好
性能比plain highlight高,因为不需要重新对高亮文本进行分词
三、fast vector highlight(文件)
对大文件而言(大于1M),性能更高
默认创建索引时添加分词
PUT /blog_website{"mappings": {"blogs": {"properties": {"title": {"type":"text","analyzer":"ik_max_word"},"content": {"type":"text","analyzer":"ik_max_word"} } } }}
查询
如果包含了那个搜索词的话,就会在那个field的文本中,对搜索词进行红色的高亮显示
posting highlight
创建索引时在要搜索的字段添加”index_options”: “offsets”
PUT /blog_website{"mappings": {"blogs": {"properties": {"title": {"type":"text","analyzer":"ik_max_word"},"content": {"type":"text","analyzer":"ik_max_word","index_options":"offsets"} } } }}
fast vector highlight
建索引时term vector设置在mapping中
PUT /blog_website{"mappings": {"blogs": {"properties": {"title": {"type":"text","analyzer":"ik_max_word"},"content": {"type":"text","analyzer":"ik_max_word","term_vector":"with_positions_offsets"} } } }}
设置高亮标签,取代
"pre_tags": [""],"post_tags": [""],
如下:
GET/blog_website/blogs/_search {"query": {"match": {"content":"博客"} },"highlight": {"pre_tags": [""],"post_tags": [""],"fields": {"content": {"type":"plain"} } }}
设置文本片段:长度、个数
GET /_search{"query": {"match": {"user":"kimchy"} },"highlight": {"fields": {"content": {"fragment_size":150,"number_of_fragments":3,"no_match_size":150} } }}fragment_size:将要显示的文本拆成*长的一段来进行显示 (设置要显示出来的文本片段的长度,默认是100)number_of_fragments:可能高亮的文本片段有多个片段,指定显示几个片段
网友评论