# How to pass pagination to java scroll api

**URL:** <https://discuss.elastic.co/t/how-to-pass-pagination-to-java-scroll-api/315965>\
**Category:** Elasticsearch\
**Created:** [October 6, 2022, 12:10pm UTC](https://discuss.elastic.co/t/how-to-pass-pagination-to-java-scroll-api/315965 "2022-10-06T12:10:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahfuj\_asif](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahfuj_asif/32/111746_2.png) [@mahfuj\_asif](https://discuss.elastic.co/u/mahfuj_asif)\
**Post date:** [October 6, 2022, 12:10pm UTC](https://discuss.elastic.co/t/how-to-pass-pagination-to-java-scroll-api/315965/1 "2022-10-06T12:10:40Z")

</div>

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

```auto
SearchQuery searchQuery = new NativeSearchQueryBuilder()
                    .withIndices(ELASTIC_INDEX)
                    .withTypes(DOC_TYPE)
                    .withPageable(PageRequest.of(30500, BATCH_SIZE))
                    .withFields("id", "pid")
                    .build();
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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 3, 2022, 12:11pm UTC](https://discuss.elastic.co/t/how-to-pass-pagination-to-java-scroll-api/315965/2 "2022-11-03T12:11:20Z")

</div>

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