# Problem with SearchRequestBuilder.setSize

**URL:** <https://discuss.elastic.co/t/problem-with-searchrequestbuilder-setsize/10286>\
**Category:** Elasticsearch\
**Created:** [January 9, 2013, 9:12pm UTC](https://discuss.elastic.co/t/problem-with-searchrequestbuilder-setsize/10286 "2013-01-09T21:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_Bowman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_bowman/32/2546_2.png) [@Sean\_Bowman](https://discuss.elastic.co/u/Sean_Bowman)\
**Post date:** [January 9, 2013, 9:12pm UTC](https://discuss.elastic.co/t/problem-with-searchrequestbuilder-setsize/10286/1 "2013-01-09T21:12:00Z")

</div>

For some reason, when I'm using the Java API, the setSize method on  
SearchRequestBuilder appears to be ignored completely. After building my  
request, I print it out and get this:

Query: #\<SearchRequestBuilder {  
"size" : 1,  
"query" : {  
"match" : {  
"name" : {  
"query" : "testing",  
"type" : "phrase",  
"analyzer" : "english"  
}  
}  
},  
"explain" : false  
}\>

When I execute that request builder, I don't get one result back, I get all  
three (my sample data set only has three entries). But if I copy that JSON  
and submit it directly to the ElasticSearch server (embedded in my app), I  
get one result back.

Is setSize not what I should be calling to limit the number of results?

--

---

<div class="post-metadata">

**Author:** ![Sean\_Bowman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_bowman/32/2546_2.png) [@Sean\_Bowman](https://discuss.elastic.co/u/Sean_Bowman)\
**Post date:** [January 9, 2013, 9:15pm UTC](https://discuss.elastic.co/t/problem-with-searchrequestbuilder-setsize/10286/2 "2013-01-09T21:15:26Z")

</div>

Sorry, I figured it out from an older post I found after posting this. I  
was using DFS\_QUERY\_AND\_FETCH, and I should have been using  
DFS\_QUERY\_THEN\_FETCH.

On Wednesday, January 9, 2013 2:12:00 PM UTC-7, Sean Bowman wrote:

> For some reason, when I'm using the Java API, the setSize method on  
> SearchRequestBuilder appears to be ignored completely. After building my  
> request, I print it out and get this:
> 
> Query: #\<SearchRequestBuilder {  
> "size" : 1,  
> "query" : {  
> "match" : {  
> "name" : {  
> "query" : "testing",  
> "type" : "phrase",  
> "analyzer" : "english"  
> }  
> }  
> },  
> "explain" : false  
> }\>
> 
> When I execute that request builder, I don't get one result back, I get  
> all three (my sample data set only has three entries). But if I copy that  
> JSON and submit it directly to the Elasticsearch server (embedded in my  
> app), I get one result back.
> 
> Is setSize not what I should be calling to limit the number of results?

--

---

<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, 2:57am UTC](https://discuss.elastic.co/t/problem-with-searchrequestbuilder-setsize/10286/3 "2017-07-06T02:57:07Z")

</div>


