【elasticsearch】查詢結(jié)果 高亮顯示

總的來說:三種高亮顯示?

一、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è)片段

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容