Last active
August 29, 2015 14:17
-
-
Save sebnmuller/92772945f5281df54c3b to your computer and use it in GitHub Desktop.
Example Elasticsearch SearchRequestBuilder
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
// Use our autowired searchService to instantiate an Elasticsearch client | |
Client client = searchService.elasticsearchClient(host, 9300); | |
// Initialise our SRB | |
SearchRequestBuilder srb = searchService.elasticsearchSearchRequestBuilder(client, index); | |
// Add aggregations to the srb | |
srb.addAggregation(AggregationBuilders.terms("shop").field("shop").size(20)); | |
// Create our filtered query and add it to the srb | |
FilterBuilder fb = elasticsearchResultFunctions.gteDateRangeFilter("valid_to", DateTime.now()); | |
QueryBuilder qb = QueryBuilders.matchAllQuery(); | |
FilteredQueryBuilder fqb = QueryBuilders.filteredQuery(qb, fb); | |
srb = srb.setQuery(fqb); | |
// Get our response | |
response = srb.setTypes("products").setSize(30).execute().actionGet(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment