How to implement nested aggregations using java client

Here are the solution posted by rabbitbr in Stackoverflow:
elasticsearch - How to implement nested aggregations using opensearch java client - Stack Overflow