# Scroll returns inconsistent number of results

**URL:** <https://discuss.elastic.co/t/scroll-returns-inconsistent-number-of-results/118018>\
**Category:** Elasticsearch\
**Created:** [February 1, 2018, 12:33pm UTC](https://discuss.elastic.co/t/scroll-returns-inconsistent-number-of-results/118018 "2018-02-01T12:33:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Markhasin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_markhasin/32/14187_2.png) [@Dan\_Markhasin](https://discuss.elastic.co/u/Dan_Markhasin)\
**Post date:** [February 1, 2018, 12:33pm UTC](https://discuss.elastic.co/t/scroll-returns-inconsistent-number-of-results/118018/1 "2018-02-01T12:33:30Z")

</div>

We are using ElasticSearch 5.4.0 and noticed a strange behavior of the scroll API on a very specific index.  
The behavior we are seeing is that when scrolling with a simple match\_all query, the number of returned results is sometimes different than the "total" returned by ES. Sometimes it returns the exactly expected number, but sometimes it returns less.

It is happening on a specific index, that is no longer active (i.e. no new data is written to it) - we haven't seen this problem on any other index and in fact reindexing the data to a new index solves the problem because the new index doesn't exhibit the same symptoms when scrolling it.

Below is an example that demonstrates the problem (the script logic is pretty simple and of course takes into account the fact that the first response also contains hits). This is the first time we see such behavior (and we do a lot of scan&scroll queries), and I haven't seen any related issue or bug that could potentially explain it.

Any tips on how to debug this to get further information on what's going on are most welcome...

[user@localhost]/tmp\> python /tmp/test\_scroll.py  
Expected: 240773  
Total hits so far: 20000  
Total hits so far: 30000  
Total hits so far: 40000  
Total hits so far: 50000  
Total hits so far: 60000  
Total hits so far: 70000  
Total hits so far: 80000  
Total hits so far: 90000  
Total hits so far: 100000  
Total hits so far: 110000  
Total hits so far: 120000  
Total hits so far: 130000  
Total hits so far: 140000  
Total hits so far: 150000  
Total hits so far: 160000  
Total hits so far: 170000  
Total hits so far: 180000  
Total hits so far: 190000  
Total hits so far: 200000  
Total hits so far: 210000  
Total hits so far: 220000  
Total hits so far: 230000  
Total hits so far: 233032  
Got empty hits array!  
Expected: 240773  
Received: 233032

Running it again five seconds later:

[user@localhost]/tmp\> python /tmp/test\_scroll.py  
Expected: 240773  
Total hits so far: 20000  
Total hits so far: 30000  
Total hits so far: 40000  
Total hits so far: 50000  
Total hits so far: 60000  
Total hits so far: 70000  
Total hits so far: 80000  
Total hits so far: 90000  
Total hits so far: 100000  
Total hits so far: 110000  
Total hits so far: 120000  
Total hits so far: 130000  
Total hits so far: 140000  
Total hits so far: 150000  
Total hits so far: 160000  
Total hits so far: 170000  
Total hits so far: 180000  
Total hits so far: 190000  
Total hits so far: 200000  
Total hits so far: 210000  
Total hits so far: 220000  
Total hits so far: 230000  
Total hits so far: 240000  
Total hits so far: 240773  
Got empty hits array!  
Expected: 240773  
Received: 240773

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 1, 2018, 12:37pm UTC](https://discuss.elastic.co/t/scroll-returns-inconsistent-number-of-results/118018/2 "2018-02-01T12:37:32Z")

</div>

Do you have any shards where the document count differs between the primary and replica?

---

<div class="post-metadata">

**Author:** ![Dan\_Markhasin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_markhasin/32/14187_2.png) [@Dan\_Markhasin](https://discuss.elastic.co/u/Dan_Markhasin)\
**Post date:** [February 1, 2018, 12:42pm UTC](https://discuss.elastic.co/t/scroll-returns-inconsistent-number-of-results/118018/3 "2018-02-01T12:42:45Z")

</div>

Based on the output of \_stats/?level=shard, there are no such shards.  
All primary and replica shards have the same number of documents (based on docs.count). There are however differences in the number of deleted documents between a primary and the replica (where primary has 0 deleted documents but replica has some), but not sure it's related.

It's also worth mentioning that the number of returned results is always the same - it is either 240773 (which is the correct number) or 233032, never any other number.

---

<div class="post-metadata">

**Author:** ![Dan\_Markhasin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_markhasin/32/14187_2.png) [@Dan\_Markhasin](https://discuss.elastic.co/u/Dan_Markhasin)\
**Post date:** [February 8, 2018, 6:58am UTC](https://discuss.elastic.co/t/scroll-returns-inconsistent-number-of-results/118018/4 "2018-02-08T06:58:13Z")

</div>

Any additional insights? I'm still seeing the same issue on the same index (and only on that index)

---

<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:** [March 8, 2018, 6:58am UTC](https://discuss.elastic.co/t/scroll-returns-inconsistent-number-of-results/118018/5 "2018-03-08T06:58:16Z")

</div>

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