【elasticsearch】查询结果 高亮显示

总的来说:三种高亮显示 

一、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:可能高亮的文本片段有多个片段,指定显示几个片段

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容