【解决方案1】:

对不起,我迟到了!但是,如果您还没有找到解决方案,您可以尝试以下方法:

SearchResponse<YourClass> response = client.search(b -> b
                .index("your_index")                 
                .aggregations("first_agg",a->a.terms(t->t.field("my_field"))
                 .aggregations("sub_agg", s->s.avg(av->av.field("other_field")))),
                YourClass.class);

【讨论】: