eselasticsearch 커서 조회 페이지 조회

//
Integer currentPage = 1;
Integer pageSize = 10;
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
// 
boolQueryBuilder.must(QueryBuilders.wildcardQuery("orderNo.keyword", "*" + filters.get(key).toString() + "*"));
// 
Date startDate = DateUtils.parseDate(filters.get(key).toString() + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
Date endDate = DateUtils.parseDate(filters.get(key).toString() + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
boolQueryBuilder.must(QueryBuilders.rangeQuery("flights.flightDate").lte(endDate.getTime()).gte(startDate.getTime()));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(boolQueryBuilder).size(pageSize);
//searchSourceBuilder.sort("createTime", SortOrder.DESC);
SearchRequest searchRequest = new SearchRequest(ORDER_INDEX);
searchRequest.source(searchSourceBuilder);
//
// 
SearchResponse searchResponse= ScrollSearchUtils.scrollSearchAll(currentPage, pageSize, restHighLevelClient, searchRequest);SearchHits hits = searchResponse.getHits();List list = new ArrayList<>();
if (searchResponse != null && hits.getHits().length > 0) {
for (SearchHit hit : searchResponse.getHits().getHits()) {
OrderEntry order = JSON.parseObject(hit.getSourceAsString(), OrderEntry.class);
list.add(order);
}
return list;
}
private static SearchResponse scrollSearchAll(int currentPage, int pageSize, RestHighLevelClient restHighLevelClient, SearchRequest searchRequest) throws IOException {
    int from = (currentPage - 1) * pageSize;
    int size = pageSize;
    // 
    Scroll scroll = new Scroll(TimeValue.timeValueMinutes(3L));
    searchRequest.scroll(scroll);
    SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
    String scrollId = searchResponse.getScrollId();
    SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId);
    scrollRequest.scroll(scroll);
    int maxNum = from / size;
    for (int i = 0; i < maxNum; i++) {
        searchResponse = restHighLevelClient.scroll(scrollRequest, RequestOptions.DEFAULT);
    }
    // 
    if (scrollId != null) {
        ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
        clearScrollRequest.addScrollId(scrollId);
        restHighLevelClient.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
    }
    return searchResponse;
}

좋은 웹페이지 즐겨찾기