use of org.elasticsearch.search.aggregations.bucket.terms.InternalTerms in project alien4cloud by alien4cloud.
the class ESGenericSearchDAO method parseAggregations.
/**
* Parse aggregations and set facets to the given non null FacetedSearchResult instance.
*
* @param searchResponse The search response that contains aggregation results.
* @param facetedSearchResult The instance in which to set facets.
* @param aggregationQueryManager If not null the data of the FacetedSearchResult will be processed from an aggregation based on the given manager.
*/
private void parseAggregations(SearchResponse searchResponse, FacetedSearchResult facetedSearchResult, IAggregationQueryManager aggregationQueryManager) {
if (searchResponse.getAggregations() == null) {
return;
}
List<Aggregation> internalAggregationsList = searchResponse.getAggregations().asList();
if (internalAggregationsList.size() == 0) {
return;
}
Map<String, FacetedSearchFacet[]> facetMap = Maps.newHashMap();
for (Aggregation aggregation : internalAggregationsList) {
if (aggregationQueryManager != null && aggregation.getName().equals(aggregationQueryManager.getQueryAggregation().getName())) {
aggregationQueryManager.setData(getJsonMapper(), getClassFromTypeFunc(), facetedSearchResult, aggregation);
} else if (aggregation instanceof InternalTerms) {
InternalTerms internalTerms = (InternalTerms) aggregation;
List<FacetedSearchFacet> facets = new ArrayList<>();
for (int i = 0; i < internalTerms.getBuckets().size(); i++) {
Terms.Bucket bucket = internalTerms.getBuckets().get(i);
facets.add(new FacetedSearchFacet(bucket.getKey(), bucket.getDocCount()));
}
// Find the missing aggregation
internalAggregationsList.stream().filter(missingAggregation -> missingAggregation instanceof InternalMissing && missingAggregation.getName().equals("missing_" + internalTerms.getName())).findAny().ifPresent(missingAggregation -> {
InternalMissing internalMissingAggregation = (InternalMissing) missingAggregation;
if (internalMissingAggregation.getDocCount() > 0) {
facets.add(new FacetedSearchFacet(null, internalMissingAggregation.getDocCount()));
}
});
facetMap.put(internalTerms.getName(), facets.toArray(new FacetedSearchFacet[facets.size()]));
} else {
log.debug("Aggregation is not a facet aggregation (terms) ignore. Name: {} ,Type: {}", aggregation.getName(), aggregation.getClass().getName());
}
}
facetedSearchResult.setFacets(facetMap);
}
Aggregations