SearchRequest API question, possible feature request?


(Lukáš Vlček) #1

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


(Shay Banon) #2

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


(Lukáš Vlček) #3

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.comwrote:

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


(Shay Banon) #4

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)> 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


(system) #5