# How to pass type in preparesearch java api?

**URL:** <https://discuss.elastic.co/t/how-to-pass-type-in-preparesearch-java-api/6731>\
**Category:** Elasticsearch\
**Created:** [February 16, 2012, 3:49pm UTC](https://discuss.elastic.co/t/how-to-pass-type-in-preparesearch-java-api/6731 "2012-02-16T15:49:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [February 16, 2012, 3:49pm UTC](https://discuss.elastic.co/t/how-to-pass-type-in-preparesearch-java-api/6731/1 "2012-02-16T15:49:17Z")

</div>

hi,  
i want to not only pass the index name but also the type to preparesearch  
java api. i couldn't figure out how to do it. can someone help?

i have indexed my documents using a index name, type and id. now i want to  
search and restrict the results to a given type.

thanks

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 16, 2012, 5:17pm UTC](https://discuss.elastic.co/t/how-to-pass-type-in-preparesearch-java-api/6731/2 "2012-02-16T17:17:34Z")

</div>

prepareSearch(...) returns a SearchRequestBuilder, which itself has a  
setTypes(...) method which takes a String vararg as a parameter.

[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java#L63](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java#L63)

eg:  
SearchRequestBuilder searchBuilder =  
client.prepareSearch("my\_index").setTypes("my\_type");

--  
Ivan

On Thu, Feb 16, 2012 at 7:49 AM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com) wrote:

> hi,  
> i want to not only pass the index name but also the type to preparesearch  
> java api. i couldn't figure out how to do it. can someone help?
> 
> i have indexed my documents using a index name, type and id. now i want to  
> search and restrict the results to a given type.
> 
> thanks

---

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [February 16, 2012, 5:22pm UTC](https://discuss.elastic.co/t/how-to-pass-type-in-preparesearch-java-api/6731/3 "2012-02-16T17:22:12Z")

</div>

thanks ivan.. i saw that after sending the mail!

On Thu, Feb 16, 2012 at 9:17 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> prepareSearch(...) returns a SearchRequestBuilder, which itself has a  
> setTypes(...) method which takes a String vararg as a parameter.
> 
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java#L63](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java#L63)
> 
> eg:  
> SearchRequestBuilder searchBuilder =  
> client.prepareSearch("my\_index").setTypes("my\_type");
> 
> --  
> Ivan
> 
> On Thu, Feb 16, 2012 at 7:49 AM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com)  
> wrote:
> 
> > hi,  
> > i want to not only pass the index name but also the type to preparesearch  
> > java api. i couldn't figure out how to do it. can someone help?
> > 
> > i have indexed my documents using a index name, type and id. now i want  
> > to  
> > search and restrict the results to a given type.
> > 
> > thanks

---

<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:39am UTC](https://discuss.elastic.co/t/how-to-pass-type-in-preparesearch-java-api/6731/4 "2017-07-06T03:39:05Z")

</div>


