Convert SQL query to Java Elastic Query

I am using Transport client to query ES. Need to convert below sql query to Java Queries:

SELECT id,max(timestamp2)
FROM table
GROUP BY id
AVING timestamp1 > "2017-07-13T21:01:00.013Z"

I know TermsQueryBuilder and AggregationBuilder can be used for this one.

But I am unable to get it right can some one please help ?

Given you already have another thread with a bunch of people helping, it's going to be easier to continue the discussion there, as it also has a bit more context :slight_smile: