Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
QueryBuilder query = QueryBuilders.boolQuery().filter(QueryBuilders.termQuery("username", username))
.filter(QueryBuilders.rangeQuery("transactionDateTime").from(startDateTime).to(endDateTime));
TermsBuilder withUsername = AggregationBuilders.terms("username").field("username");
TermsBuilder withCurrency = AggregationBuilders.terms("currency").field("currency");
SumBuilder withTotalAmount = AggregationBuilders.sum("totalAmount").field("amount");
SearchResponse response = getClient().prepareSearch(getIndex()).setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setTypes(getType()).setSize(0).setQuery(query).addAggregation(withUsername)
.addAggregation(withCurrency).addAggregation(withTotalAmount).execute().actionGet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment