# Add Json aggregation string to SearchRequestBuilder in java API

**URL:** https://discuss.elastic.co/t/add-json-aggregation-string-to-searchrequestbuilder-in-java-api/91639
**Category:** Elasticsearch
**Created:** [July 3, 2017, 1:34pm UTC](https://discuss.elastic.co/t/add-json-aggregation-string-to-searchrequestbuilder-in-java-api/91639 "2017-07-03T13:34:51Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![philv](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@philv](https://discuss.elastic.co/u/philv)
#### Post date: [July 4, 2017, 2:34pm UTC](https://discuss.elastic.co/t/add-json-aggregation-string-to-searchrequestbuilder-in-java-api/91639/2 "2017-07-04T14:34:51Z")

</div>

My question is essentially the same as this one:

> [@How to use the ElasticSearch Java API to build an Aggregation from JSON](https://discuss.elastic.co/t/how-to-use-the-elasticsearch-java-api-to-build-an-aggregation-from-json/70773):
>
> Hi everyone, My code has an ElasticSearch query and aggregations in JSON format, and wants to call the ElasticSearch Java API. For the Query portion, I can use WrapperQuery to build the query from the JSON as so: val query = Json.obj( "query\_string" -\> Json.obj("query" -\> "\*")) val aggs = Json.obj( "gender" -\> Json.obj("terms" -\> Json.obj("field": "gender")), "age" -\> Json.obj("terms" -\> Json.obj("field": "age"))) val aggsRequestBuilder = new SearchRequestBuilder(client) .setIndi…

I presume the answer is the same ?

---

_[View the full topic](https://discuss.elastic.co/t/add-json-aggregation-string-to-searchrequestbuilder-in-java-api/91639)._
