# SearchRequest API question, possible feature request?

**URL:** <https://discuss.elastic.co/t/searchrequest-api-question-possible-feature-request/4810>\
**Category:** Elasticsearch\
**Created:** [July 7, 2011, 2:57pm UTC](https://discuss.elastic.co/t/searchrequest-api-question-possible-feature-request/4810 "2011-07-07T14:57:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 7, 2011, 2:57pm UTC](https://discuss.elastic.co/t/searchrequest-api-question-possible-feature-request/4810/1 "2011-07-07T14:57:52Z")

</div>

Hi,

there are two methods in SearchRequest API:

SearchRequest#indices(String[] indices)  
SearchRequest#types(String... types)

Would it be possible to change (or may be better add) the "indices"  
signature

SearchRequest#indices(String... indices)

?

It would allow for more easy API I think. Right now I have to write  
something like the following:

SearchSourceBuilder sb = ...  
Requests.searchRequest()  
.indices(new String[]{indexName}) // \<- and this can be simplified  
.types(myType)  
.searchType(SearchType.QUERY\_AND\_FETCH)  
.timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
.source(sb)

Requests.searchRequest()  
.indices(indexName) // \<- after proposed change  
.types(myType)  
.searchType(SearchType.QUERY\_AND\_FETCH)  
.timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
.source(sb)

Regards,  
Lukas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 7, 2011, 2:59pm UTC](https://discuss.elastic.co/t/searchrequest-api-question-possible-feature-request/4810/2 "2011-07-07T14:59:54Z")

</div>

PUshed, but you should really use SearchRequestBuilder (client.prepareSearch) which already have a setIndices(String...) sig.

On Thursday, July 7, 2011 at 5:57 PM, Lukáš Vlček wrote:

> Hi,
> 
> there are two methods in SearchRequest API:
> 
> SearchRequest#indices(String indices)  
> SearchRequest#types(String... types)
> 
> Would it be possible to change (or may be better add) the "indices" signature
> 
> SearchRequest#indices(String... indices)
> 
> ?
> 
> It would allow for more easy API I think. Right now I have to write something like the following:
> 
> SearchSourceBuilder sb = ...  
> Requests.searchRequest()  
> .indices(new String{indexName}) // \<- and this can be simplified  
> .types(myType)  
> .searchType(SearchType.QUERY\_AND\_FETCH)  
> .timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
> .source(sb)
> 
> Requests.searchRequest()  
> .indices(indexName) // \<- after proposed change  
> .types(myType)  
> .searchType(SearchType.QUERY\_AND\_FETCH)  
> .timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
> .source(sb)
> 
> Regards,  
> Lukas

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 8, 2011, 11:52am UTC](https://discuss.elastic.co/t/searchrequest-api-question-possible-feature-request/4810/3 "2011-07-08T11:52:07Z")

</div>

The problem I see with this API is that it requires a client instance. When  
I was using SearchSourceBuilder I did not have to have an instance of client  
but still I was able to write a code that construct the query which was very  
useful for business logic unit tests. Or is there a way how to get instance  
of SearchRequestBuilder and pass it client instance at a later time? (its  
constructor tells me that there is not).

In other words SearchRequestBuilder API seems to be a little more elegant  
but testing it is more heavyweight then SearchSourceBuilder.

Regards,  
Lukas

On Thu, Jul 7, 2011 at 4:59 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> PUshed, but you should really use SearchRequestBuilder  
> (client.prepareSearch) which already have a setIndices(String...) sig.
> 
> On Thursday, July 7, 2011 at 5:57 PM, Lukáš Vlček wrote:
> 
> Hi,
> 
> there are two methods in SearchRequest API:
> 
> SearchRequest#indices(String indices)  
> SearchRequest#types(String... types)
> 
> Would it be possible to change (or may be better add) the "indices"  
> signature
> 
> SearchRequest#indices(String... indices)
> 
> ?
> 
> It would allow for more easy API I think. Right now I have to write  
> something like the following:
> 
> SearchSourceBuilder sb = ...  
> Requests.searchRequest()  
> .indices(new String{indexName}) // \<- and this can be simplified  
> .types(myType)  
> .searchType(SearchType.QUERY\_AND\_FETCH)  
> .timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
> .source(sb)
> 
> Requests.searchRequest()  
> .indices(indexName) // \<- after proposed change  
> .types(myType)  
> .searchType(SearchType.QUERY\_AND\_FETCH)  
> .timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
> .source(sb)
> 
> Regards,  
> Lukas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 8, 2011, 8:50pm UTC](https://discuss.elastic.co/t/searchrequest-api-question-possible-feature-request/4810/4 "2011-07-08T20:50:07Z")

</div>

Then use SearchSourceBuilder.

On Friday, July 8, 2011 at 2:52 PM, Lukáš Vlček wrote:

> The problem I see with this API is that it requires a client instance. When I was using SearchSourceBuilder I did not have to have an instance of client but still I was able to write a code that construct the query which was very useful for business logic unit tests. Or is there a way how to get instance of SearchRequestBuilder and pass it client instance at a later time? (its constructor tells me that there is not).
> 
> In other words SearchRequestBuilder API seems to be a little more elegant but testing it is more heavyweight then SearchSourceBuilder.
> 
> Regards,  
> Lukas
> 
> On Thu, Jul 7, 2011 at 4:59 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > PUshed, but you should really use SearchRequestBuilder (client.prepareSearch) which already have a setIndices(String...) sig.
> > 
> > On Thursday, July 7, 2011 at 5:57 PM, Lukáš Vlček wrote:
> > 
> > > Hi,
> > > 
> > > there are two methods in SearchRequest API:
> > > 
> > > SearchRequest#indices(String indices)  
> > > SearchRequest#types(String... types)
> > > 
> > > Would it be possible to change (or may be better add) the "indices" signature
> > > 
> > > SearchRequest#indices(String... indices)
> > > 
> > > ?
> > > 
> > > It would allow for more easy API I think. Right now I have to write something like the following:
> > > 
> > > SearchSourceBuilder sb = ...  
> > > Requests.searchRequest()  
> > > .indices(new String{indexName}) // \<- and this can be simplified  
> > > .types(myType)  
> > > .searchType(SearchType.QUERY\_AND\_FETCH)  
> > > .timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
> > > .source(sb)
> > > 
> > > Requests.searchRequest()  
> > > .indices(indexName) // \<- after proposed change  
> > > .types(myType)  
> > > .searchType(SearchType.QUERY\_AND\_FETCH)  
> > > .timeout(TimeValue.timeValueSeconds(timeoutInSeconds))  
> > > .source(sb)
> > > 
> > > Regards,  
> > > Lukas

---

<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:01am UTC](https://discuss.elastic.co/t/searchrequest-api-question-possible-feature-request/4810/5 "2017-07-06T04:01:13Z")

</div>


