首页/数据/NoSQL 速查/highlight 关键词高亮
本包目录(322 条)
MongoDB99 条
Elasticsearch89 条
ClickHouse56 条时序与列式28 条选型与架构50 条

highlight 关键词高亮

highlight 让匹配片段在结果中带标记返回:fields 指定要高亮的字段,pre_tags/post_tags 自定义包裹标签,number_of_fragments 控制片段数量。

NoSQL 速查数据更新于 2026-10-12
常用参数fields、pre_tags/post_tags、fragment_size、number_of_fragments
常用 typeunified(默认)、plain、fvh(需 fast vector highlighter 映射)
相关开关require_field_match 默认 true:只高亮命中的字段

示例

示例
GET /my-index/_search
{
  "query": { "match": { "content": "elasticsearch tutorial" } },
  "highlight": {
    "pre_tags": ["<em>"],
    "post_tags": ["</em>"],
    "fields": {
      "content": { "fragment_size": 120, "number_of_fragments": 2 }
    }
  }
}
高亮文本来自 _source 或词向量,字段关闭 _source 又未开 term_vector 时无法高亮。

易错点

  • 对 keyword 字段高亮会显示整串而非片段,长文本要配 text 字段
  • number_of_fragments 设为 0 表示返回整段内容,大文档下响应会明显变大

数据来源与参考

  • Elasticsearch Guide: Highlighting
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌