@[TOC]
Highlight the query
A highlighted query is a keyword that you type, and it’s presented to the user in a special character style, so that the user knows why the result was retrieved. Okay
The highlighted data, itself a field in the document, is returned to you separately as highlight. ES provides a highlight attribute at the same level as query.
- Fragment_size: Specifies how many characters are displayed in the highlighted data;
- Pre_tag: Specifies a prefix tag, such as
<font color="red">
- Post_tags: Specifies postfix tags, such as
</font>
- Field: Specifies which field is highlighted
1.1. Example: According to the SMSContent field, the syntax of the charm field is high;
1.1.1 RESTful code
POST /sms-logs-index/_search
{
"query": {
"match": {
"smsContent": "魅力"
}
},
"highlight": {
"fields": {
"smsContent": {}
},
"pre_tags": "<font color='red'>",
"post_tags": "</font>",
"fragment_size": 10
}
}
1.1.2. Java code
@test public void Height () throws IOException {@test public void Height () throws IOException {@test public void Height () throws IOException {@test public void Height () throws IOException SearchRequest(index); // 2, SearchSourceBuilder = new SearchSourceBuilder(); / / 2.1 searchSourceBuilder, query conditions. The query (QueryBuilders. MatchQuery (" smsContent, "" charm")); HighlightBuilder = new highlightBuilder (); highlightBuilder = new highlightBuilder (); highlightBuilder.field("smsContent", 10) .preTags("<font color='red'>") .postTags("</font>"); searchSourceBuilder.highlighter(highlightBuilder); searchRequest.source(searchSourceBuilder); SearchResponse = Client. Search (SearchRequest, RequestOptions. Default); // 4, print for (searchHit hit: resp.getHits().getHits()) { System.out.println(hit.getHighlightFields().get("smsContent")); }}
Pay attention to my public number [big data], more dry goods