# getHits() and totalHits() give different no. of results set

**URL:** https://discuss.elastic.co/t/gethits-and-totalhits-give-different-no-of-results-set/24556
**Category:** Elasticsearch
**Created:** [June 29, 2015, 3:14pm UTC](https://discuss.elastic.co/t/gethits-and-totalhits-give-different-no-of-results-set/24556 "2015-06-29T15:14:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Anand\_kumar](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anand\_kumar](https://discuss.elastic.co/u/Anand_kumar)
#### Post date: [June 29, 2015, 3:14pm UTC](https://discuss.elastic.co/t/gethits-and-totalhits-give-different-no-of-results-set/24556/1 "2015-06-29T15:14:13Z")

</div>

Hi All,

Am using elastic version 1.2.1, below is my searchquery, here the fromIndex refers to dynamic value which fetches result based on the page no,(10 results for each page) but when I try to iterate over the ResultSet, I got diff values for getHits() and totalHits(). For instance, I got 10 hits for each page and resultset shows different no of searchhits over the iterations, sometimes as 7, 8 and 9.

SearchRequestBuilder requestBuilder = client.prepareSearch()  
.setSearchType(SearchType.QUERY\_THEN\_FETCH)  
.setQuery(filterQuery)  
.setFrom(fromIndex).setExplain(false)

Any suggestion would be helpful, thanks in advance.

Regards,  
Anand

---

<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: [June 29, 2015, 4:05pm UTC](https://discuss.elastic.co/t/gethits-and-totalhits-give-different-no-of-results-set/24556/2 "2015-06-29T16:05:31Z")

</div>

Moving this to the Elasticsearch category since it is not to do with User Groups

---

<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:04am UTC](https://discuss.elastic.co/t/gethits-and-totalhits-give-different-no-of-results-set/24556/3 "2017-07-06T00:04:45Z")

</div>


