Updating this old thread as @monde shared with me a solution he found on SOF:
val aggsRequestBuilder = new SearchRequestBuilder(client)
.setIndices(index())
.setQuery(QueryBuilders.wrapperQuery(query.toString())
.setAggregations(agg.toString().getBytes())