總的來說:三種高亮顯示?
一、plain highlight(默認(rèn))?
二、posting highlight(性能)?
對磁盤的消耗更少?
將文本切割為句子,并且對句子進(jìn)行高亮,效果更好?
性能比plain highlight高,因?yàn)椴恍枰匦聦Ω吡廖谋具M(jìn)行分詞?
三、fast vector highlight(文件)?
對大文件而言(大于1M),性能更高
默認(rèn)創(chuàng)建索引時(shí)添加分詞
PUT /blog_website{"mappings": {"blogs": {"properties": {"title": {"type":"text","analyzer":"ik_max_word"},"content": {"type":"text","analyzer":"ik_max_word"}? ? ? }? ? }? }}
查詢
如果包含了那個(gè)搜索詞的話,就會在那個(gè)field的文本中,對搜索詞進(jìn)行紅色的高亮顯示
posting highlight
創(chuàng)建索引時(shí)在要搜索的字段添加”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
建索引時(shí)term vector設(shè)置在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"}? ? ? }? ? }? }}
設(shè)置高亮標(biāo)簽,取代
"pre_tags": [""],"post_tags": [""],
如下:
GET/blog_website/blogs/_search {"query": {"match": {"content":"博客"}? },"highlight": {"pre_tags": [""],"post_tags": [""],"fields": {"content": {"type":"plain"}? ? }? }}
設(shè)置文本片段:長度、個(gè)數(shù)
GET /_search{"query": {"match": {"user":"kimchy"}? ? },"highlight": {"fields": {"content": {"fragment_size":150,"number_of_fragments":3,"no_match_size":150}? ? ? ? }? ? }}fragment_size:將要顯示的文本拆成*長的一段來進(jìn)行顯示? ? (設(shè)置要顯示出來的文本片段的長度,默認(rèn)是100)number_of_fragments:可能高亮的文本片段有多個(gè)片段,指定顯示幾個(gè)片段