# I am not getting how to use SearchResponse in Aggregation

**URL:** <https://discuss.elastic.co/t/i-am-not-getting-how-to-use-searchresponse-in-aggregation/113062>\
**Category:** Elasticsearch\
**Created:** [December 23, 2017, 4:46am UTC](https://discuss.elastic.co/t/i-am-not-getting-how-to-use-searchresponse-in-aggregation/113062 "2017-12-23T04:46:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gou02rav32](https://avatars.discourse-cdn.com/v4/letter/g/d2c977/32.png) [@gou02rav32](https://discuss.elastic.co/u/gou02rav32)\
**Post date:** [December 23, 2017, 4:46am UTC](https://discuss.elastic.co/t/i-am-not-getting-how-to-use-searchresponse-in-aggregation/113062/1 "2017-12-23T04:46:50Z")

</div>

Here one client method creating problem for me. I went through java api of elastic search but still not getting that client() usage and node usage.  
Please help me out.

Here is the syntax.  
SearchResponse sr = **_node.client()_**.prepareSearch()  
.addAggregation(  
AggregationBuilders.terms("by\_country").field("country")  
.subAggregation(AggregationBuilders.dateHistogram("by\_year")  
.field("dateOfBirth")  
.dateHistogramInterval(DateHistogramInterval.YEAR)  
.subAggregation(AggregationBuilders.avg("avg\_children").field("children"))  
)  
)  
.execute().actionGet();

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 23, 2017, 9:31am UTC](https://discuss.elastic.co/t/i-am-not-getting-how-to-use-searchresponse-in-aggregation/113062/2 "2017-12-23T09:31:44Z")

</div>

I'd use the REST client: [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html)

---

<div class="post-metadata">

**Author:** ![gou02rav32](https://avatars.discourse-cdn.com/v4/letter/g/d2c977/32.png) [@gou02rav32](https://discuss.elastic.co/u/gou02rav32)\
**Post date:** [December 26, 2017, 1:37am UTC](https://discuss.elastic.co/t/i-am-not-getting-how-to-use-searchresponse-in-aggregation/113062/3 "2017-12-26T01:37:32Z")

</div>

Thank you, I also want to import some JSON file through rest client using bulk API. Unfortunately, I'm unable to do, could you please show me the syntax or something related to it that I can do it.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 26, 2017, 7:26am UTC](https://discuss.elastic.co/t/i-am-not-getting-how-to-use-searchresponse-in-aggregation/113062/4 "2017-12-26T07:26:17Z")

</div>

This?

[https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-bulk.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-bulk.html)

---

<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:** [January 23, 2018, 7:26am UTC](https://discuss.elastic.co/t/i-am-not-getting-how-to-use-searchresponse-in-aggregation/113062/5 "2018-01-23T07:26:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
