# Incomplete results for scan / scroll searches

**URL:** <https://discuss.elastic.co/t/incomplete-results-for-scan-scroll-searches/5789>\
**Category:** Elasticsearch\
**Created:** [November 7, 2011, 9:23am UTC](https://discuss.elastic.co/t/incomplete-results-for-scan-scroll-searches/5789 "2011-11-07T09:23:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [November 7, 2011, 9:23am UTC](https://discuss.elastic.co/t/incomplete-results-for-scan-scroll-searches/5789/1 "2011-11-07T09:23:38Z")

</div>

I have a little (Java) based test playing with the scan / scroll API. It is  
basically working but I am always missing a single element in the last  
scroll response. This is what I am doing conceptually:

1. Index 1000 documents and run a index refresh (index has default of 5  
shards)
2. Run 'matchAll' search with search type = 'scan', size=100, timeout of  
30 seconds
3. Run a loop of scroll request with the previous scroll id until I get  
no more hits

I found that the number of total hits is correctly reported as 1000. The  
first scroll response carries the expected 500 hits (number of shards \*  
100). However the second (last) scroll response only has 499 hits. It seems  
that the last document is missing. Has someone observed similar issues ?

---

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [November 7, 2011, 11:05am UTC](https://discuss.elastic.co/t/incomplete-results-for-scan-scroll-searches/5789/2 "2011-11-07T11:05:33Z")

</div>

_Update_

The problem was most likely on my side. I expected each scroll to have 500  
elements. What I actually get for the 1000 elements is 3 responses: 1 = 500  
hits, 2 = 499 hits, 3 = 1 hit. I get all 1000 elements so there seems to be  
no bug. I still find the sizes a little strange ... maybe someone can shed  
some light on this.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 7, 2011, 12:03pm UTC](https://discuss.elastic.co/t/incomplete-results-for-scan-scroll-searches/5789/3 "2011-11-07T12:03:01Z")

</div>

Hi Jan

> The problem was most likely on my side. I expected each scroll to have  
> 500 elements. What I actually get for the 1000 elements is 3  
> responses: 1 = 500 hits, 2 = 499 hits, 3 = 1 hit. I get all 1000  
> elements so there seems to be no bug. I still find the sizes a little  
> strange ... maybe someone can shed some light on this.

If you request $size results when scanning, it gives you a maximum of  
$size results from each shard.

So if $size == 10, and you have 5 shards, you could get a maximum of 50  
results. The actual number will vary, depending on which shards contain  
the documents.

For example, if you have a total of 25 documents, on two shards, but 20  
of them are on shard 1, then you would get:

- first request: 15 results:
  - 10 from shard 1
  - 5 from shard 2

- second request: 10 results
  - 10 from shard 1

clint

---

<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, 3:49am UTC](https://discuss.elastic.co/t/incomplete-results-for-scan-scroll-searches/5789/4 "2017-07-06T03:49:48Z")

</div>


