# Help with JestClient equivalent of Elasticsearch java api query - how to add searchtype and facetbuilder

**URL:** <https://discuss.elastic.co/t/help-with-jestclient-equivalent-of-elasticsearch-java-api-query-how-to-add-searchtype-and-facetbuilder/11085>\
**Category:** Elasticsearch\
**Created:** [March 10, 2013, 6:20am UTC](https://discuss.elastic.co/t/help-with-jestclient-equivalent-of-elasticsearch-java-api-query-how-to-add-searchtype-and-facetbuilder/11085 "2013-03-10T06:20:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mihir\_M\_2](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Mihir\_M\_2](https://discuss.elastic.co/u/Mihir_M_2)\
**Post date:** [March 10, 2013, 6:20am UTC](https://discuss.elastic.co/t/help-with-jestclient-equivalent-of-elasticsearch-java-api-query-how-to-add-searchtype-and-facetbuilder/11085/1 "2013-03-10T06:20:03Z")

</div>

Hi,

I am having trouble translating following ElasticSearch NodeClient query  
to JestClient. I have something along the lines of

SearchResponse sr = client.prepareSearch("myindex")  
.setTypes("myproducts")  
.setSearchType(SearchType.COUNT)  
.setQuery(QueryBuilders.matchAllQuery())  
.addFacet(FacetBuilders.termsFacet("facetname").field("someattr"))  
.execute().actionGet();

I know how to set index, type and query but am stuck at searchtype, facet.

Would it be ok to create a SearchRequestBuilder with null client and pass  
it the TermQueryBuilder and FacetBuilder and then convert the query to  
string and pass it to JestClient (Search.createQuueryWithBuilders)?

thanks,  
mihir

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![ferhatsb](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@ferhatsb](https://discuss.elastic.co/u/ferhatsb)\
**Post date:** [March 11, 2013, 11:43am UTC](https://discuss.elastic.co/t/help-with-jestclient-equivalent-of-elasticsearch-java-api-query-how-to-add-searchtype-and-facetbuilder/11085/2 "2013-03-11T11:43:17Z")

</div>

I have replied through other channels but maybe others can use this  
solution;

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();  
searchSourceBuilder.query(QueryBuilders.matchAllQuery());  
searchSourceBuilder.facet(FacetBuilders.termsFacet("tag").field("tag").size(10)).facet(FacetBuilders.termsFacet("user").field("user").size(10));  
String query = searchSourceBuilder.toString();

Search search = new Search(query);  
search.addIndex("terms\_facet");  
search.addType("document");  
JestResult result = client.execute(search);  
List termsFacets = result.getFacets(TermsFacet.class);

On Sunday, March 10, 2013 8:20:03 AM UTC+2, Mihir M wrote:

> Hi,
> 
> I am having trouble translating following Elasticsearch NodeClient query  
> to JestClient. I have something along the lines of
> 
> SearchResponse sr = client.prepareSearch("myindex")  
> .setTypes("myproducts")  
> .setSearchType(SearchType.COUNT)  
> .setQuery(QueryBuilders.matchAllQuery())  
> .addFacet(FacetBuilders.termsFacet("facetname").field("someattr"))  
> .execute().actionGet();
> 
> I know how to set index, type and query but am stuck at searchtype, facet.
> 
> Would it be ok to create a SearchRequestBuilder with null client and pass  
> it the TermQueryBuilder and FacetBuilder and then convert the query to  
> string and pass it to JestClient (Search.createQuueryWithBuilders)?
> 
> thanks,  
> mihir

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:47am UTC](https://discuss.elastic.co/t/help-with-jestclient-equivalent-of-elasticsearch-java-api-query-how-to-add-searchtype-and-facetbuilder/11085/3 "2017-07-06T02:47:14Z")

</div>


