Problem with binary sub aggregations

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 :

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

This looks like a bug. I've raised this issue on github for it:

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

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