Terms aggregation on a nested field using Java SDK?

So calling aggregations and passing a static map didn't seem to work, but this did:

            Aggregation subAggregation = new Aggregation.Builder()
                    .terms(new TermsAggregation.Builder().field("domain.subdomains").size(100).exclude(e -> e.terms(List.of(subdomain))).build())
                    .build();

            Aggregation nestedAggregation = new Aggregation.Builder()
                    .nested(new NestedAggregation.Builder().path("domain").build())
                    .aggregations("subdomains", subAggregation)
                    .build();

Thanks for your help!