# Builder setSize(X) returns a lot more than X?

**URL:** <https://discuss.elastic.co/t/builder-setsize-x-returns-a-lot-more-than-x/4832>\
**Category:** Elasticsearch\
**Created:** [July 11, 2011, 7:48am UTC](https://discuss.elastic.co/t/builder-setsize-x-returns-a-lot-more-than-x/4832 "2011-07-11T07:48:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimOnGmail](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TimOnGmail](https://discuss.elastic.co/u/TimOnGmail)\
**Post date:** [July 11, 2011, 7:48am UTC](https://discuss.elastic.co/t/builder-setsize-x-returns-a-lot-more-than-x/4832/1 "2011-07-11T07:48:30Z")

</div>

Hi all...

So I'm trying to use Elastic Search, but am having some difficulties.

The latest one is, in code like this:

* * *

```
  SearchRequestBuilder builder = client.prepareSearch(index);
  builder = builder.setSearchType(SearchType.DFS_QUERY_AND_FETCH);
  builder = builder.setQuery(new

```

QueryStringQueryBuilder(queryString));  
builder = builder.setFrom(startIndex);  
builder = builder.setSize(maxResults);  
builder = builder.setExplain(true);  
ListenableActionFuture future =  
builder.execute();  
response = future.actionGet(MAX\_WAIT\_MILLIS);  
SearchHits hits = response.getHits();

* * *

hits.getTotalHits() is some reasonable number

However, hits.getHits().length is always BIGGER than maxResults.

From the documentation, it looks like I"m supposed to just get, at  
most, maxResults hits back, but I'm always getting more than that  
back.

Does anyone know why that might be happening? Am I doing something  
wrong here?

- Tim

---

<div class="post-metadata">

**Author:** ![Hari\_Shankar](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@Hari\_Shankar](https://discuss.elastic.co/u/Hari_Shankar)\
**Post date:** [July 11, 2011, 8:36am UTC](https://discuss.elastic.co/t/builder-setsize-x-returns-a-lot-more-than-x/4832/2 "2011-07-11T08:36:30Z")

</div>

Hi,

Query and fetch would return size\*number of shards results. (  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/search-type.html)).

hari

On Mon, Jul 11, 2011 at 1:18 PM, TimOnGmail [timbessie@gmail.com](mailto:timbessie@gmail.com) wrote:

> Hi all...
> 
> So I'm trying to use Elastic Search, but am having some difficulties.
> 
> The latest one is, in code like this:
> 
> * * *
> 
> ```
> SearchRequestBuilder builder = client.prepareSearch(index);
> builder = builder.setSearchType(SearchType.DFS_QUERY_AND_FETCH);
> builder = builder.setQuery(new
> 
> ```
> 
> QueryStringQueryBuilder(queryString));  
> builder = builder.setFrom(startIndex);  
> builder = builder.setSize(maxResults);  
> builder = builder.setExplain(true);  
> ListenableActionFuture future =  
> builder.execute();  
> response = future.actionGet(MAX\_WAIT\_MILLIS);  
> SearchHits hits = response.getHits();
> 
> * * *
> 
> hits.getTotalHits() is some reasonable number
> 
> However, hits.getHits().length is always BIGGER than maxResults.
> 
> From the documentation, it looks like I"m supposed to just get, at  
> most, maxResults hits back, but I'm always getting more than that  
> back.
> 
> Does anyone know why that might be happening? Am I doing something  
> wrong here?
> 
> - Tim

---

<div class="post-metadata">

**Author:** ![TimOnGmail](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TimOnGmail](https://discuss.elastic.co/u/TimOnGmail)\
**Post date:** [July 11, 2011, 5:25pm UTC](https://discuss.elastic.co/t/builder-setsize-x-returns-a-lot-more-than-x/4832/3 "2011-07-11T17:25:34Z")

</div>

Ahhh, thanks Hari!

- Tim

On Jul 11, 1:36 am, Hari Shankar [shaan.h...@gmail.com](mailto:shaan.h...@gmail.com) wrote:

> Hi,
> 
> Query and fetch would return size\*number of shards results. ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/search-type.html)).
> 
> hari
> 
> On Mon, Jul 11, 2011 at 1:18 PM, TimOnGmail [timbes...@gmail.com](mailto:timbes...@gmail.com) wrote:
> 
> > Hi all...
> 
> > So I'm trying to use Elastic Search, but am having some difficulties.
> 
> > The latest one is, in code like this:
> 
> > * * *
> 
> > ```
> > SearchRequestBuilder builder = client.prepareSearch(index);
> > builder = builder.setSearchType(SearchType.DFS_QUERY_AND_FETCH);
> > builder = builder.setQuery(new
> > 
> > ```
> > 
> > QueryStringQueryBuilder(queryString));  
> > builder = builder.setFrom(startIndex);  
> > builder = builder.setSize(maxResults);  
> > builder = builder.setExplain(true);  
> > ListenableActionFuture future =  
> > builder.execute();  
> > response = future.actionGet(MAX\_WAIT\_MILLIS);  
> > SearchHits hits = response.getHits();
> 
> > * * *
> 
> > hits.getTotalHits() is some reasonable number
> 
> > However, hits.getHits().length is always BIGGER than maxResults.
> 
> > From the documentation, it looks like I"m supposed to just get, at  
> > most, maxResults hits back, but I'm always getting more than that  
> > back.
> 
> > Does anyone know why that might be happening? Am I doing something  
> > wrong here?
> 
> > - Tim

---

<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, 4:00am UTC](https://discuss.elastic.co/t/builder-setsize-x-returns-a-lot-more-than-x/4832/4 "2017-07-06T04:00:59Z")

</div>


