# SearchSourceBuilder.from accepts an integer

**URL:** https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300
**Category:** Elasticsearch
**Created:** [November 3, 2017, 11:20am UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300 "2017-11-03T11:20:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kieran](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@kieran](https://discuss.elastic.co/u/kieran)
#### Post date: [November 3, 2017, 11:20am UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/1 "2017-11-03T11:20:56Z")

</div>

Hi

The Java class SearchSourceBuilder has a method 'from', which takes an int. So if I'm paginating I will set this value. However, the SearchResponse has a method .getHits().getTotalHits() which returns a long.

When dealing with results sets larger than Integer.MAX\_VALUE, how should I request a page with a starting element greater than Integer.MAX\_VALUE?

Thanks  
Kieran

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 3, 2017, 11:42am UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/2 "2017-11-03T11:42:53Z")

</div>

You can't do that.

from+size is limited by default to 10000.

---

<div class="post-metadata">

### Author: ![kieran](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@kieran](https://discuss.elastic.co/u/kieran)
#### Post date: [November 3, 2017, 11:44am UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/3 "2017-11-03T11:44:50Z")

</div>

How would I paginate on a result set that is greater than 10000?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 3, 2017, 11:46am UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/4 "2017-11-03T11:46:39Z")

</div>

Are you sure a user would like to get back the "less" relevant result?

If you want to extract all the resultset, you can look at the scroll API. [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-scroll.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-scroll.html)  
If you want to do deep pagination, you can look at search after: [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-search-after.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-search-after.html)

But you can't access directly to page 134512 for example.

---

<div class="post-metadata">

### Author: ![kieran](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@kieran](https://discuss.elastic.co/u/kieran)
#### Post date: [November 3, 2017, 1:59pm UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/5 "2017-11-03T13:59:10Z")

</div>

The index I am designing is for transactions. So it's conceivable that I want to get all transactions for a user, where that user has more than 10000 transactions, and a front end client wants to paginate through that data. So it's not about relevance. Should there be another way of me paginating through this kind of data?

I had a look at the 'search-after' functionality but it's not ideal to have to ask the front end to supply the last transaction from the previous page.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 3, 2017, 2:15pm UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/6 "2017-11-03T14:15:03Z")

</div>

You can increase the default limit of 10000 hits but you really need to understand the consequences.

Look at `index.max_result_window` in [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index-modules.html#dynamic-index-settings](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index-modules.html#dynamic-index-settings)

---

<div class="post-metadata">

### Author: ![kieran](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@kieran](https://discuss.elastic.co/u/kieran)
#### Post date: [November 3, 2017, 2:22pm UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/7 "2017-11-03T14:22:05Z")

</div>

I see. I imagine it would be rare for our transaction searches to contain more than 10000, but we would need to support these use cases.

Does increasing index.max\_result\_window affect the performance of all search queries?

What happens if max\_result\_window is 10000 and page 1 of a search containing more than 10000 total results is requested? Would an error be received?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 3, 2017, 4:02pm UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/8 "2017-11-03T16:02:33Z")

</div>

> Does increasing index.max\_result\_window affect the performance of all search queries?

If you are not using it (like with size=10, from=0), no.

But, the problem is not only performance. My concern is more about the memory usage and the risk you take of producing out of memory exceptions.

> What happens if max\_result\_window is 10000 and page 1 of a search containing more than 10000 total results is requested?

Yes.

> I imagine it would be rare for our transaction searches to contain more than 10000, but we would need to support these use cases.

I believe you have something like a date of transaction in your dataset.  
Just sort by date ascending or descending and then you don't need to do deep pagination...  
Add some faceted navigation and you're done!

I really think that users should never have to go to last page.

But may be your users are asking themselves other questions that you can solve differently with elasticsearch. Aggregations is the key IMHO.

---

<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: [December 1, 2017, 4:02pm UTC](https://discuss.elastic.co/t/searchsourcebuilder-from-accepts-an-integer/106300/9 "2017-12-01T16:02:41Z")

</div>

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