zoukankan      html  css  js  c++  java
  • elasticsearch5.2 高亮java代码

    /**
    * 高亮代码
    */

    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();
    }

    }

  • 相关阅读:
    UVA
    UVA
    母函数
    快速排序
    集合:set
    stringstream转换
    大学期间的任务
    Devc++贪吃蛇
    Vector容器
    广度优先遍历
  • 原文地址:https://www.cnblogs.com/zengxiaoyi36/p/9261068.html
Copyright © 2011-2022 走看看