# How to pass the raw aggregation query in JSON using REST HighLevelClient in E.S 5.6.9?

**URL:** https://discuss.elastic.co/t/how-to-pass-the-raw-aggregation-query-in-json-using-rest-highlevelclient-in-e-s-5-6-9/141675
**Category:** Elasticsearch
**Created:** [July 26, 2018, 12:44am UTC](https://discuss.elastic.co/t/how-to-pass-the-raw-aggregation-query-in-json-using-rest-highlevelclient-in-e-s-5-6-9/141675 "2018-07-26T00:44:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kant\_kodali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kant_kodali/32/50637_2.png) [@kant\_kodali](https://discuss.elastic.co/u/kant_kodali)
#### Post date: [July 26, 2018, 12:44am UTC](https://discuss.elastic.co/t/how-to-pass-the-raw-aggregation-query-in-json-using-rest-highlevelclient-in-e-s-5-6-9/141675/1 "2018-07-26T00:44:09Z")

</div>

How do I pass raw json aggregation query to REST HighLevelClient in E.S 5.6.9?

For Example, Given the json below how do I pass the json below as is to the REST HighLevelClient?

```
{
    "aggs" : {
        "genres" : {
            "terms" : { "field" : "genre" }
        }
    }

}
```

---

<div class="post-metadata">

### Author: ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)
#### Post date: [July 27, 2018, 6:50pm UTC](https://discuss.elastic.co/t/how-to-pass-the-raw-aggregation-query-in-json-using-rest-highlevelclient-in-e-s-5-6-9/141675/2 "2018-07-27T18:50:51Z")

</div>

Hi,  
providing json is not really what the high-level REST client is meant for, it's more to avoid having to deal with json. You may be able to achieve parsing that json into a temporary SearchSourceBuilder using its fromXContent method, then you can retrieve the aggs in object format using the `aggregations` getter and set them back to another `SearchSourceBuilder` instance, which I presume would have also other sections set (query etc.) using the `aggregation` setter.

---

<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: [August 24, 2018, 6:50pm UTC](https://discuss.elastic.co/t/how-to-pass-the-raw-aggregation-query-in-json-using-rest-highlevelclient-in-e-s-5-6-9/141675/3 "2018-08-24T18:50:54Z")

</div>

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