ElasticSearch排序Java api简单Demo

代码:

   String time1 = ConstValue.GetCurrentDate();
        SortBuilder sortBuilder = SortBuilders.fieldSort("tfp_save_time")
                .order(SortOrder.DESC).ignoreUnmapped(true);

        SearchResponse scrollResp = client
                .prepareSearch("flume-" + time1 + "-content-news")
                .addHighlightedField("scc_content")
                .addHighlightedField("scm_title")
                .setQuery(ConstValue.queryBuilder22(requestSignal.getQuery()))
                .addSort(sortBuilder).addHighlightedField("scc_title")
                .setHighlighterPreTags("<em>").setHighlighterPostTags("</em>")
                .setFrom((requestSignal.getPage() - 1) * 20).setSize(20)
                .execute().actionGet();

 官方粘的:

client.prepareSearch(indexName).setTypes(typeName)
      .setQuery(query)
      .addSort(fieldSort("activity").order(DESC).missing("_last"))
      .setSize(limit)
      .execute().actionGet();

 The .missing("_last") cannot be applied to boolean fields.

posted @ 2017-09-28 09:12  人艰不拆_zmc  阅读(470)  评论(0编辑  收藏  举报