I can't use builder pattern and lambda because of a lot of aggregation that are optional. But I got hint from your code. I used Aggregation.Builder().term() instead of AggregationBuilders.terms().
Now it's possible to add sub aggregations and it was solved.
Thank you very much for your help.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.