# Iterate over the whole response without size 'predefined' using JAVA API

**URL:** <https://discuss.elastic.co/t/iterate-over-the-whole-response-without-size-predefined-using-java-api/25867>\
**Category:** Elasticsearch\
**Created:** [July 20, 2015, 5:37am UTC](https://discuss.elastic.co/t/iterate-over-the-whole-response-without-size-predefined-using-java-api/25867 "2015-07-20T05:37:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)\
**Post date:** [July 20, 2015, 5:37am UTC](https://discuss.elastic.co/t/iterate-over-the-whole-response-without-size-predefined-using-java-api/25867/1 "2015-07-20T05:37:43Z")

</div>

Hi,

How to make my search response to give all the documents matched to the relevant query without using any  
setSize(10) with predefined value.  
How can I achieve this????

**Right now am using :**  
response = client.prepareSearch(index).setTypes(type)  
.setQuery(QueryBuilders.matchAllQuery()).setSize(10).execute()  
.actionGet();

Here when I would like to get the complete response and i dont know the size in advance, then how can I achieve the complete response without size declaration. (or) any other way to get the complete data??

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 20, 2015, 5:43am UTC](https://discuss.elastic.co/t/iterate-over-the-whole-response-without-size-predefined-using-java-api/25867/2 "2015-07-20T05:43:54Z")

</div>

Perhaps scan and scroll is what you want? [https://www.elastic.co/guide/en/elasticsearch/guide/current/scan-scroll.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/scan-scroll.html)

---

<div class="post-metadata">

**Author:** ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)\
**Post date:** [July 21, 2015, 6:56am UTC](https://discuss.elastic.co/t/iterate-over-the-whole-response-without-size-predefined-using-java-api/25867/3 "2015-07-21T06:56:29Z")

</div>

Can you provide me the Java API for that scroll operation by including that in the above example or any examples on how to use the scroll with Java API????????

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 21, 2015, 8:26am UTC](https://discuss.elastic.co/t/iterate-over-the-whole-response-without-size-predefined-using-java-api/25867/4 "2015-07-21T08:26:34Z")

</div>

Here is a link to the Java API documentation on using the scroll API: [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/scrolling.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/scrolling.html)

---

<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:** [July 6, 2017, 12:00am UTC](https://discuss.elastic.co/t/iterate-over-the-whole-response-without-size-predefined-using-java-api/25867/5 "2017-07-06T00:00:13Z")

</div>


