14、Elasticsearch 搜索数据:高亮、验证与排序指南

Elasticsearch 搜索数据:高亮、验证与排序指南

1. 高亮功能概述

高亮是在搜索结果中显示查询词匹配部分的过程。在日常浏览网页时,我们经常能看到高亮的搜索结果。在 Elasticsearch 中,我们可以利用其高亮功能来增强应用的搜索体验。

2. 开始使用高亮

若要在文档的标题字段中高亮匹配的单词,可发送如下查询:

{
  "query" : {
    "term" : {
      "title" : "crime"
    }
  },
  "highlight" : {
    "fields" : {
      "title" : {}
    }
  }
}

响应结果如下:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.19178301,
    "hits" : [ {
      "_index" : "library",
      "_type" : "book",
      "_id" : "4",
      "_score" : 0.19178301, 
      "_source" : { 
        "title": "Crime and Punis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值