org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder Java Examples
The following examples show how to use
org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlogRepositoryCustomImpl.java From Spring-5.0-Projects with MIT License | 8 votes |
public List<Comment> getCommentsForStatus(String status,int from, int size) { IncludeExclude includeExclude = new IncludeExclude(status, null); NestedAggregationBuilder aggregation = AggregationBuilders.nested("aggChild", "comments"). subAggregation(AggregationBuilders.terms("aggStatsComment"). field("comments.status"). includeExclude(includeExclude). subAggregation(AggregationBuilders.topHits("aggSortComment").size(10).sort("comments.createdDate", SortOrder.DESC)) ); SearchResponse response = elasticsearchTemplate.getClient().prepareSearch("blog") .setTypes("blog") .addAggregation(aggregation) .execute().actionGet(); List<Aggregation> responseAgg = response.getAggregations().asList(); return getAllCommentsWithStatusFromJson(responseAgg.get(0).toString()); }
Example #2
Source File: BlogRepositoryCustomImpl.java From Spring-5.0-Projects with MIT License | 5 votes |
public int getCurrentChildSequence(String blogId,String parentCommentId) { int currentChildSeq=0; TermQueryBuilder termQueryBuilder = new TermQueryBuilder("comments.parentId", parentCommentId); NestedAggregationBuilder aggregationBuilder = AggregationBuilders.nested("aggChild", "comments").subAggregation( AggregationBuilders.filter("filterParentId", termQueryBuilder).subAggregation( AggregationBuilders.max("maxChildSeq").field("comments.childSequence"))); TermQueryBuilder rootTermQueryBuilder = new TermQueryBuilder("_id", blogId); SearchResponse response = elasticsearchTemplate.getClient().prepareSearch("blog") .setTypes("blog") .setQuery(rootTermQueryBuilder) .addAggregation(aggregationBuilder) .execute().actionGet(); if(response !=null) { if(response.getAggregations() !=null) { List<Aggregation> aggLst = response.getAggregations().asList(); if(aggLst !=null) { Aggregation resultAgg = aggLst.get(0); if(resultAgg !=null) { currentChildSeq = getMaxChildSequenceFromJson(resultAgg.toString()); } } } } //Adding one to set next sequence. currentChildSeq=currentChildSeq+1; return currentChildSeq; }
Example #3
Source File: AggregationQueryAction.java From elasticsearch-sql with Apache License 2.0 | 4 votes |
private AggregationBuilder wrapNestedIfNeeded(AggregationBuilder nestedBuilder, boolean reverseNested) { if (!reverseNested) return nestedBuilder; if (reverseNested && !(nestedBuilder instanceof NestedAggregationBuilder)) return nestedBuilder; //we need to jump back to root return AggregationBuilders.reverseNested(nestedBuilder.getName() + "_REVERSED").subAggregation(nestedBuilder); }
Example #4
Source File: BlogRepositoryCustomImpl.java From Spring-5.0-Projects with MIT License | 3 votes |
public List<Comment> getAllComments(int from, int size){ NestedAggregationBuilder aggregation = AggregationBuilders.nested("aggChild", "comments"). subAggregation(AggregationBuilders.topHits("aggSortComment").sort("comments.createdDate", SortOrder.DESC).from(from).size(size)); SearchResponse response = elasticsearchTemplate.getClient().prepareSearch("blog") .setTypes("blog") .addAggregation(aggregation) .execute().actionGet(); List<Aggregation> responseAgg = response.getAggregations().asList(); return getAllCommentsFromJson(responseAgg.get(0).toString()); }