首页 > 其他 > 详细

es 滚动查询二

时间:2020-12-02 10:52:49      阅读:40      评论:0      收藏:0      [点我收藏+]
  /**
     * es 游标获取总数
     *
     * @param tableName 表名
     * @param query     查询条件
     */
    public void esScrollDataHelp(String tableName, QueryBuilder query) {
        TransportClient client = ElasticSearchUtil.getClient();
        SearchResponse scrollResp = client.prepareSearch(tableName)
                .setTypes(tableName)
                .setScroll(new TimeValue(60000))
                .setQuery(query)
                .addSort(SortBuilders.fieldSort("_doc"))
                .setSize(100).get();
        long totalCount = scrollResp.getHits().getTotalHits();// 获取总数量
        System.out.println("totalCount:" + totalCount);
        do {
            for (SearchHit hit : scrollResp.getHits().getHits()) {
                String id = hit.getId();
                System.out.println(id);
            }
            scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
        } while (scrollResp.getHits().getHits().length != 0);
    }

 

es 滚动查询二

原文:https://www.cnblogs.com/luweiweicode/p/14071983.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!