Scripted field in Elastic aggregation using High level Client

Did you look at this page?

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-aggregation-builders.html

And this method: https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.5.2/org/elasticsearch/search/aggregations/support/ValuesSourceAggregationBuilder.html#script()