标签:color stat rac dex etag field oid index red
/**
* 高亮代码
*/
public static void search(QueryBuilder qb, String index) {
SearchRequestBuilder sr = transportClient.prepareSearch(index);// .setTypes("infor2");
HighlightBuilder highlightBuilder = new HighlightBuilder();// .field("*").requireFieldMatch(true);
highlightBuilder.preTags("<span style=\"color:red\">");
highlightBuilder.postTags("</span>");
highlightBuilder.field("perFoName");
try {
SearchResponse sResponse = sr.setQuery(qb).setSize(20).highlighter(highlightBuilder).get();
SearchHits hits = sResponse.getHits();
if (hits.totalHits() > 0) {
for (SearchHit hit : hits) {
Map<String, HighlightField> hig = hit.getHighlightFields();
HighlightField emailfiled = hit.getHighlightFields().get("perFoName");
if (emailfiled != null) {
Text[] text = emailfiled.getFragments();
for (Text str : text) {
System.out.println("88888==" + str.string());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
标签:color stat rac dex etag field oid index red
原文地址:https://www.cnblogs.com/zengxiaoyi36/p/9261068.html