ElasticSearch ( 八 ) 高亮显示

9.高亮highlight

9.1.highlight 关键字

可以让符合条件的文档中的关键词高亮。

highlight相关属性:

pre_tags 前缀标签
post_tags 后缀标签
tags_schema 设置为 styled可以使用内置高亮样式
require_field_match 多字段高亮需要设置为false

GET /db_idx4/_search
{
  "query": {
    "term": {
      "address": {
        "value": "王者"
      }
    }
  },
  "highlight": {
    "fields": {
      "*": {}
    }
  }
}

9.2.自定义高亮html标签

可以在highlight中使用 pre_tags和 post_tags。

GET /db_idx4/_search
{
  "query": {
    "term": {
      "address": {
        "value": "王者"
      }
    }
  },
  "highlight": {
    "post_tags": [
      ""
    ],
    "pre_tags": [
      ""
    ],
    "fields": {
      "*": {}
    }
  }
} 


9.3 多字段高亮

GET /db_idx4/_search
{
  "query": {
    "term": {
      "address": {
        "value": "王者"
      }
    }
  },
  "highlight": {
    "pre_tags": [
      ""
    ],
    "post_tags": [
      ""
    ],
    "require_field_match": "false",
    "fields": {
      "address": {},
      "desc": {}
    }
  }
} 

你可能感兴趣的:(ElasticSearch,elasticsearch,大数据,搜索引擎)