# Problem with binary sub aggregations

**URL:** <https://discuss.elastic.co/t/problem-with-binary-sub-aggregations/1727>\
**Category:** Elasticsearch\
**Created:** [June 2, 2015, 1:44pm UTC](https://discuss.elastic.co/t/problem-with-binary-sub-aggregations/1727 "2015-06-02T13:44:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clement\_tourriere](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clement_tourriere/32/479_2.png) [@clement\_tourriere](https://discuss.elastic.co/u/clement_tourriere)\
**Post date:** [June 2, 2015, 1:44pm UTC](https://discuss.elastic.co/t/problem-with-binary-sub-aggregations/1727/1 "2015-06-02T13:44:01Z")

</div>

Hello everyone,

In a custom plugin, I would like to build an aggregation containing a sub aggregation that can be passed as parameter. I have a REST end point /\_customagg/ that can accept aggregations as POST parameters : {"aggs": "myagg": {"terms": {"field": "test"}}}

In the plugin code, I need to be able to "merge" my aggregation builder with aggregations in parameter as sub aggregation (XContentBuilder).

When using subaggregation method from AggregationBuilder class, it seems to produce wrong query.

I've made a gist to reproduce my problem : [https://gist.github.com/clement-tourriere/3571d3dc22a1cd33534f](https://gist.github.com/clement-tourriere/3571d3dc22a1cd33534f)

I don't know if there is a better way to achieve what I'm trying to do, all other suggestions are welcome ;).

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [June 2, 2015, 2:18pm UTC](https://discuss.elastic.co/t/problem-with-binary-sub-aggregations/1727/2 "2015-06-02T14:18:15Z")

</div>

This looks like a bug. I've raised this issue on github for it: [https://github.com/elastic/elasticsearch/issues/11457](https://github.com/elastic/elasticsearch/issues/11457)

Thanks for raising this issue. Unfortunately I can't think of a workaround for this.

---

<div class="post-metadata">

**Author:** ![clement\_tourriere](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clement_tourriere/32/479_2.png) [@clement\_tourriere](https://discuss.elastic.co/u/clement_tourriere)\
**Post date:** [June 3, 2015, 1:15pm UTC](https://discuss.elastic.co/t/problem-with-binary-sub-aggregations/1727/3 "2015-06-03T13:15:12Z")

</div>

Thank you Colin for your response and your quick fix. Just need to wait for the next release now :).

---

<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, 12:09am UTC](https://discuss.elastic.co/t/problem-with-binary-sub-aggregations/1727/4 "2017-07-06T00:09:57Z")

</div>


