How to pass pagination to java scroll api

I am trying to fetch all data from elastic index with scroll id.

SearchQuery searchQuery = new NativeSearchQueryBuilder()
                    .withPageable(PageRequest.of(30500, BATCH_SIZE))
                    .withFields("id", "pid")
users = elasticsearchTemplate.startScroll(SCROLL_TIMEOUT, searchQuery, User.class);

But the pagination is not working. It always returns all the documents from page 0. There are total 30500 documents in the index, so when i set .withPageable(PageRequest.of(30500, BATCH_SIZE)) with batch size 10, there should not be any data returned, but it still returns data. What i am doing wrong here?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.