Created
April 5, 2016 10:23
-
-
Save geneqew/ff282c0b7057703223ebaa70976f0649 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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