如果返回的结果集中很多符合条件的结果,那怎么能⼀眼就能看到我们想要的那个结果呢?
1.查询
默认是em标签
GET /nba_lastest/_search { "query": { "match": { "displayNameEn": "Adams" } }, "highlight": { "fields": { "displayNameEn":{} } } }
效果:
{ "took" : 178, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : 5.6049123, "hits" : [ { "_index" : "nba_20200202", "_type" : "_doc", "_id" : "2", "_score" : 5.6049123, "_source" : { "countryEn" : "New Zealand", "teamName" : "雷霆", "birthDay" : 743140800000, "country" : "新西兰", "teamCityEn" : "Oklahoma City", "code" : "steven_adams", "displayAffiliation" : "Pittsburgh/New Zealand", "displayName" : "斯蒂文 亚当斯", "schoolType" : "College", "teamConference" : "西部", "teamConferenceEn" : "Western", "weight" : "120.2 公斤", "teamCity" : "俄克拉荷马城", "playYear" : 6, "jerseyNo" : "12", "teamNameEn" : "Thunder", "draft" : 2013, "displayNameEn" : "Steven Adams", "heightValue" : 2.13, "birthDayStr" : "1993-07-20", "position" : "中锋", "age" : 26, "playerId" : "203500" }, "highlight" : { "displayNameEn" : [ "Steven <em>Adams</em>" ] } }, { "_index" : "nba_20200202", "_type" : "_doc", "_id" : "1", "_score" : 5.6049123, "_source" : { "countryEn" : "United States", "teamName" : "老鹰", "birthDay" : 831182400000, "country" : "美国", "teamCityEn" : "Atlanta", "code" : "jaylen_adams", "displayAffiliation" : "United States", "displayName" : "杰伦 亚当斯", "schoolType" : "College", "teamConference" : "东部", "teamConferenceEn" : "Eastern", "weight" : "86.2 公斤", "teamCity" : "亚特兰大", "playYear" : 1, "jerseyNo" : "10", "teamNameEn" : "Hawks", "draft" : 2018, "displayNameEn" : "Jaylen Adams", "heightValue" : 1.88, "birthDayStr" : "1996-05-04", "position" : "后卫", "age" : 25, "playerId" : "1629121" }, "highlight" : { "displayNameEn" : [ "Jaylen <em>Adams</em>" ] } } ] } }
2.自定义标签
GET /nba_lastest/_search { "query": { "match": { "displayNameEn": "Adams" } }, "highlight": { "fields": { "displayNameEn":{ "pre_tags": ["<h1>"], "post_tags": ["</h1>"] } } } }
效果:
{ "took" : 9, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : 5.6049123, "hits" : [ { "_index" : "nba_20200202", "_type" : "_doc", "_id" : "2", "_score" : 5.6049123, "_source" : { "countryEn" : "New Zealand", "teamName" : "雷霆", "birthDay" : 743140800000, "country" : "新西兰", "teamCityEn" : "Oklahoma City", "code" : "steven_adams", "displayAffiliation" : "Pittsburgh/New Zealand", "displayName" : "斯蒂文 亚当斯", "schoolType" : "College", "teamConference" : "西部", "teamConferenceEn" : "Western", "weight" : "120.2 公斤", "teamCity" : "俄克拉荷马城", "playYear" : 6, "jerseyNo" : "12", "teamNameEn" : "Thunder", "draft" : 2013, "displayNameEn" : "Steven Adams", "heightValue" : 2.13, "birthDayStr" : "1993-07-20", "position" : "中锋", "age" : 26, "playerId" : "203500" }, "highlight" : { "displayNameEn" : [ "Steven <h1>Adams</h1>" ] } }, { "_index" : "nba_20200202", "_type" : "_doc", "_id" : "1", "_score" : 5.6049123, "_source" : { "countryEn" : "United States", "teamName" : "老鹰", "birthDay" : 831182400000, "country" : "美国", "teamCityEn" : "Atlanta", "code" : "jaylen_adams", "displayAffiliation" : "United States", "displayName" : "杰伦 亚当斯", "schoolType" : "College", "teamConference" : "东部", "teamConferenceEn" : "Eastern", "weight" : "86.2 公斤", "teamCity" : "亚特兰大", "playYear" : 1, "jerseyNo" : "10", "teamNameEn" : "Hawks", "draft" : 2018, "displayNameEn" : "Jaylen Adams", "heightValue" : 1.88, "birthDayStr" : "1996-05-04", "position" : "后卫", "age" : 25, "playerId" : "1629121" }, "highlight" : { "displayNameEn" : [ "Jaylen <h1>Adams</h1>" ] } } ] } }