How to search multiple indexes with the JAVA Client when the index names are known only at runtime

I'm having some issues with the limitations of the Java Client API when
dealing with search requests across multiple indexes.

What works:

  • I have two indexes "myIndex_one" and "myIndex_two".
  • I can execute a search across multiple indexes if I know their name
    before compilation

client.prepareSearch("myIndex_one","myIndex_two").setQuery(query).execute().
get()

as I'm using the method:

SearchRequestBuilder prepareSearch(String... indices); // 

Client.java:line 355

What doesn't work:

I would like to be able to execute a search request across multiple indexes
defined at runtime.
As such, instead of "myIndex_one" and "myIndex_two" I would like to have a
list of indexes
<"myIndex_1",..."myIndex_n"> defined at runtime and then just call
List myIndexes = new ArrayList("myIndex1","myIndex2","myIndex8");
client.prepareSearch(myIndexes).setQuery(query).execute().get();

But right now the ES JAVA Client doesn't have an overloaded prepareSearch
method like:

SearchRequestBuilder prepareSearch(List<String> indices); 

Question:
Is there any workaround for this? Or maybe I'm missing some method
somewhere that might offer the same functionality?

Thanks
Paul.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Simply convert the list in a array of Strings. Java varargs expects an
Array.

--
Ivan

On Fri, Feb 1, 2013 at 1:10 PM, Paul Sabou paul.sabou@gmail.com wrote:

I'm having some issues with the limitations of the Java Client API when
dealing with search requests across multiple indexes.

What works:

  • I have two indexes "myIndex_one" and "myIndex_two".
  • I can execute a search across multiple indexes if I know their name
    before compilation

client.prepareSearch("myIndex_one","myIndex_two").setQuery(query).execute
().get()

as I'm using the method:

SearchRequestBuilder prepareSearch(String... indices); //

Client.java:line 355

What doesn't work:

I would like to be able to execute a search request across multiple
indexes defined at runtime.
As such, instead of "myIndex_one" and "myIndex_two" I would like to have a
list of indexes
<"myIndex_1",..."myIndex_n"> defined at runtime and then just call
List myIndexes = new ArrayList("myIndex1","myIndex2","myIndex8");
client.prepareSearch(myIndexes).setQuery(query).execute().get();

But right now the ES JAVA Client doesn't have an overloaded prepareSearch
method like:

SearchRequestBuilder prepareSearch(List<String> indices);

Question:
Is there any workaround for this? Or maybe I'm missing some method
somewhere that might offer the same functionality?

Thanks
Paul.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks Ivan. Indeed this is the right way to use it.

I have been mislead by the fact that I'm trying to do that from Scala and
I'm not familiar enough with the Scala vargs tricks.

As others might get stuck in this trivial issue, I'm posting the Scala
solution below:

val indexes = List("myIndex_one","myIndex_two","myIndex_three")
val result = client.prepareSearch(indexes:_*).setQuery("some ES query")

Cheers
Paul.

On Friday, February 1, 2013 10:26:18 PM UTC+1, Ivan Brusic wrote:

Simply convert the list in a array of Strings. Java varargs expects an
Array.

--
Ivan

On Fri, Feb 1, 2013 at 1:10 PM, Paul Sabou <paul....@gmail.com<javascript:>

wrote:

I'm having some issues with the limitations of the Java Client API when
dealing with search requests across multiple indexes.

What works:

  • I have two indexes "myIndex_one" and "myIndex_two".
  • I can execute a search across multiple indexes if I know their name
    before compilation

client.prepareSearch("myIndex_one","myIndex_two").setQuery(query).execute
().get()

as I'm using the method:

SearchRequestBuilder prepareSearch(String... indices); // 

Client.java:line 355

What doesn't work:

I would like to be able to execute a search request across multiple
indexes defined at runtime.
As such, instead of "myIndex_one" and "myIndex_two" I would like to have
a list of indexes
<"myIndex_1",..."myIndex_n"> defined at runtime and then just call
List myIndexes = new ArrayList("myIndex1","myIndex2","myIndex8");
client.prepareSearch(myIndexes).setQuery(query).execute().get();

But right now the ES JAVA Client doesn't have an overloaded prepareSearch
method like:

 SearchRequestBuilder prepareSearch(List<String> indices); 

Question:
Is there any workaround for this? Or maybe I'm missing some method
somewhere that might offer the same functionality?

Thanks
Paul.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.