Scroll api use of es

  elastic-search

Example

MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("app",app);
        SearchQuery query = new NativeSearchQueryBuilder()
                .withIndices(index)
                .withTypes(type)
                .withQuery(matchQueryBuilder)
                .withPageable(page)
                .build();
        long scollTimeInMillis = 1000;
        String scrollId = elasticsearchTemplate.scan(query, scollTimeInMillis, false);
        boolean hasRecords = true;
        long totalCount = 0;
        while (hasRecords) {
            Page<LogDetail> page = elasticsearchTemplate.scroll(scrollId, scollTimeInMillis, LogDetail.class);
            if (page.hasContent()) {
                LOGGER.info("page number:{}",page.getNumberOfElements());
                totalCount += page.getNumberOfElements();
            } else {
                hasRecords = false;
            }
        }

        //clear scroll
        elasticsearchTemplate.clearScroll(scrollId);