ElasticSearch学习

文章40 |   阅读 24260 |   点赞0

来源:https://blog.csdn.net/ywl470812087/category_9621251.html

ElasticSearch highlight搜索结果高亮显示(英文检索)

x33g5p2x  于2021-12-19 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(488)

高亮显示搜索结果(使用highlight)

#高亮搜索结果
GET /lib3/user/_search
{
  "query":{
    "match":{"interests": "changge" } 
  }, 
  "highlight": { 
    "fields": {"interests":{}}
  }
  
}
{
  "took" : 2075,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 0.6931472,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "2",
        "_score" : 0.6931472,
        "_source" : {
          "name" : "zhaoming",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 20,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu, duanlian, changge"
        },
        "highlight" : {
          "interests" : [
            "xi huan hejiu, duanlian, <em>changge</em>"
          ]
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "zhangsan",
          "address" : "bei jing chao yang qu",
          "age" : 29,
          "birthday" : "1988-10-12",
          "interests" : "xi huan tingyinyue , changge , tiaowu"
        },
        "highlight" : {
          "interests" : [
            "xi huan tingyinyue , <em>changge</em> , tiaowu"
          ]
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "3",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "lisi",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 23,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu,duanlian, changge"
        },
        "highlight" : {
          "interests" : [
            "xi huan hejiu,duanlian, <em>changge</em>"
          ]
        }
      }
    ]
  }
}

我们通过结果可知使用highlight的字段被加了一个标签,这个标签就是高亮显示标签

相关文章