# Limit results count when using sliced scroll api

**URL:** <https://discuss.elastic.co/t/limit-results-count-when-using-sliced-scroll-api/95498>\
**Category:** Elasticsearch\
**Created:** [August 2, 2017, 9:58am UTC](https://discuss.elastic.co/t/limit-results-count-when-using-sliced-scroll-api/95498 "2017-08-02T09:58:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josca](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Josca](https://discuss.elastic.co/u/Josca)\
**Post date:** [August 2, 2017, 9:58am UTC](https://discuss.elastic.co/t/limit-results-count-when-using-sliced-scroll-api/95498/1 "2017-08-02T09:58:43Z")

</div>

Hi,  
I use sliced scroll api to fetch results from Elasticsearch in parallel ([https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#sliced-scroll](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#sliced-scroll)). But I am not able to set Elasticsearch to return first milion only. Results count cab be reduced using parameter "min\_score", but it's not way I want. Is it possible to set results count even if sliced scroll method is used?  
Thanks.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [August 2, 2017, 7:57pm UTC](https://discuss.elastic.co/t/limit-results-count-when-using-sliced-scroll-api/95498/2 "2017-08-02T19:57:18Z")

</div>

`terminate_after` (bottom of this page: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html)) might work with scrolling, I'm not sure

But why not just record the number of hits that you've scrolled client-side and stop when you get to 1m?

---

<div class="post-metadata">

**Author:** ![Josca](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Josca](https://discuss.elastic.co/u/Josca)\
**Post date:** [August 3, 2017, 7:17am UTC](https://discuss.elastic.co/t/limit-results-count-when-using-sliced-scroll-api/95498/3 "2017-08-03T07:17:13Z")

</div>

Thanks, I will try "terminate\_after".

Yes, I tried this method. But when using "sliced scroll" results seems to be received in random order among slices. So when I stop after 1m received results, it's not sure I received 1m highest score results.

Example: I'm fetching results using 5 slices with size 1000. I supposed that slice 0 will receive 1000 highest score results. But it's not sure. I tested it.

---

<div class="post-metadata">

**Author:** ![Josca](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Josca](https://discuss.elastic.co/u/Josca)\
**Post date:** [August 3, 2017, 10:09am UTC](https://discuss.elastic.co/t/limit-results-count-when-using-sliced-scroll-api/95498/4 "2017-08-03T10:09:28Z")

</div>

Ok, I solved this problem. I control results count fetched with each slice and I stop fetching when defined count per slice is reached.

I don't know how to use "terminate\_after" param exactly. It stops fetching when defined count is reached, but received results have not highest score. So it's useless for me.

---

<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:** [August 31, 2017, 10:09am UTC](https://discuss.elastic.co/t/limit-results-count-when-using-sliced-scroll-api/95498/5 "2017-08-31T10:09:40Z")

</div>

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