# Searching multiple types using Groovy client

**URL:** <https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297>\
**Category:** Elasticsearch\
**Created:** [September 1, 2011, 4:25pm UTC](https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297 "2011-09-01T16:25:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manish](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Manish](https://discuss.elastic.co/u/Manish)\
**Post date:** [September 1, 2011, 4:25pm UTC](https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297/1 "2011-09-01T16:25:38Z")

</div>

I appreciate if someone can let me know how do I pass the types names  
using groovy client if I want my search to include many types . I've  
tried to pass , (comma) separated names in variable "searchTypes" in  
the code below but it didn't seem to work.  
def res = getClient().search {  
indices searchIndices  
types searchTypes  
source searchSource  
}

Thanks in advance....  
Manish

---

<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:** [September 1, 2011, 6:05pm UTC](https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297/2 "2011-09-01T18:05:43Z")

</div>

The closure you pass gets evaluated into a SearchRequest object, which has a  
method called: types(String... types). Note, you can always use the "static"  
type APIs.

On Thu, Sep 1, 2011 at 7:25 PM, Manish [singhmanishp@gmail.com](mailto:singhmanishp@gmail.com) wrote:

> I appreciate if someone can let me know how do I pass the types names  
> using groovy client if I want my search to include many types . I've  
> tried to pass , (comma) separated names in variable "searchTypes" in  
> the code below but it didn't seem to work.  
> def res = getClient().search {  
> indices searchIndices  
> types searchTypes  
> source searchSource  
> }
> 
> Thanks in advance....  
> Manish

---

<div class="post-metadata">

**Author:** ![Manish](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Manish](https://discuss.elastic.co/u/Manish)\
**Post date:** [September 2, 2011, 9:55am UTC](https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297/3 "2011-09-02T09:55:28Z")

</div>

Hi Shay,

Thanks! I got the idea how types(String... types) should be used. In  
my code these types are dynamic. I need to sometimes pass a single  
type and sometimes many types so I cannot use types(String... types)  
as it forces me to hardcode the types (Probably a method signature  
like types(String types) suits better for dynamically changing the  
types.. similar to indices method). Could you elaborate more on use of  
the "static" type APIs you mentioned or point me to some documentation  
on it. May be I find some solution there...

Best regards,  
Manish

On Sep 1, 9:05 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> The closure you pass gets evaluated into a SearchRequest object, which has a  
> method called: types(String... types). Note, you can always use the "static"  
> type APIs.
> 
> On Thu, Sep 1, 2011 at 7:25 PM, Manish [singhmani...@gmail.com](mailto:singhmani...@gmail.com) wrote:
> 
> > I appreciate if someone can let me know how do I pass the types names  
> > using groovy client if I want my search to include many types . I've  
> > tried to pass , (comma) separated names in variable "searchTypes" in  
> > the code below but it didn't seem to work.  
> > def res = getClient().search {  
> > indices searchIndices  
> > types searchTypes  
> > source searchSource  
> > }
> 
> > Thanks in advance....  
> > Manish

---

<div class="post-metadata">

**Author:** ![Manish](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Manish](https://discuss.elastic.co/u/Manish)\
**Post date:** [September 5, 2011, 8:49am UTC](https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297/4 "2011-09-05T08:49:36Z")

</div>

It would be great if someone can elaborate what is meant by " "static"  
type APIs." in this mail thread. I am new to the Elasticsearch  
world... not able to find the meaning / documentation on it.

Thanks  
Manish

On Sep 2, 12:55 pm, Manish [singhmani...@gmail.com](mailto:singhmani...@gmail.com) wrote:

> Hi Shay,
> 
> Thanks! I got the idea howtypes(String...types) should be used. In  
> my code thesetypesare dynamic. I need to sometimes pass a single  
> type and sometimes manytypesso I cannot usetypes(String...types)  
> as it forces me to hardcode thetypes(Probably a method signature  
> liketypes(String types) suits better for dynamically changing thetypes.. similar to indices method). Could you elaborate more on use of  
> the "static" type APIs you mentioned or point me to some documentation  
> on it. May be I find some solution there...
> 
> Best regards,  
> Manish
> 
> On Sep 1, 9:05 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > The closure you pass gets evaluated into a SearchRequest object, which has a  
> > method called:types(String...types). Note, you can always use the "static"  
> > type APIs.
> 
> > On Thu, Sep 1, 2011 at 7:25 PM, Manish [singhmani...@gmail.com](mailto:singhmani...@gmail.com) wrote:
> > 
> > > I appreciate if someone can let me know how do I pass thetypesnames  
> > > usinggroovyclientif I want my search to include manytypes. I've  
> > > tried to pass , (comma) separated names in variable "searchTypes" in  
> > > the code below but it didn't seem to work.  
> > > def res = getClient().search {  
> > > indices searchIndices  
> > > typessearchTypes  
> > > source searchSource  
> > > }
> 
> > > Thanks in advance....  
> > > Manish

---

<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:** [September 5, 2011, 9:10am UTC](https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297/5 "2011-09-05T09:10:46Z")

</div>

Not sure I understand, if its a single value, why can't you call types? The  
"static" method calls are just hte plain Java API calls, check the  
prepareXXX method on the groovy client (which are the same in the wrapped  
Java client).

On Fri, Sep 2, 2011 at 12:55 PM, Manish [singhmanishp@gmail.com](mailto:singhmanishp@gmail.com) wrote:

> Hi Shay,
> 
> Thanks! I got the idea how types(String... types) should be used. In  
> my code these types are dynamic. I need to sometimes pass a single  
> type and sometimes many types so I cannot use types(String... types)  
> as it forces me to hardcode the types (Probably a method signature  
> like types(String types) suits better for dynamically changing the  
> types.. similar to indices method). Could you elaborate more on use of  
> the "static" type APIs you mentioned or point me to some documentation  
> on it. May be I find some solution there...
> 
> Best regards,  
> Manish
> 
> On Sep 1, 9:05 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > The closure you pass gets evaluated into a SearchRequest object, which  
> > has a  
> > method called: types(String... types). Note, you can always use the  
> > "static"  
> > type APIs.
> > 
> > On Thu, Sep 1, 2011 at 7:25 PM, Manish [singhmani...@gmail.com](mailto:singhmani...@gmail.com) wrote:
> > 
> > > I appreciate if someone can let me know how do I pass the types names  
> > > using groovy client if I want my search to include many types . I've  
> > > tried to pass , (comma) separated names in variable "searchTypes" in  
> > > the code below but it didn't seem to work.  
> > > def res = getClient().search {  
> > > indices searchIndices  
> > > types searchTypes  
> > > source searchSource  
> > > }
> > 
> > > Thanks in advance....  
> > > Manish

---

<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, 3:55am UTC](https://discuss.elastic.co/t/searching-multiple-types-using-groovy-client/5297/6 "2017-07-06T03:55:12Z")

</div>


