Пример #1
0
 public SearchResult(SearchResponse resp, Select select) throws SqlParseException {
   Aggregations aggs = resp.getAggregations();
   if (aggs.get("filter") != null) {
     InternalFilter inf = aggs.get("filter");
     aggs = inf.getAggregations();
   }
   if (aggs.get("group by") != null) {
     InternalTerms terms = aggs.get("group by");
     Collection<Bucket> buckets = terms.getBuckets();
     this.total = buckets.size();
     results = new ArrayList<>(buckets.size());
     for (Bucket bucket : buckets) {
       Map<String, Object> aggsMap = toAggsMap(bucket.getAggregations().getAsMap());
       aggsMap.put("docCount", bucket.getDocCount());
       results.add(aggsMap);
     }
   } else {
     results = new ArrayList<>(1);
     this.total = 1;
     Map<String, Object> map = new HashMap<>();
     for (Aggregation aggregation : aggs) {
       map.put(aggregation.getName(), covenValue(aggregation));
     }
     results.add(map);
   }
 }
Пример #2
0
 // Response helpers
 protected Multimap<String, FacetValue> processAggregations(Aggregations aggregations) {
   Multimap<String, FacetValue> stats = ArrayListMultimap.create();
   if (aggregations != null) {
     for (Aggregation aggregation : aggregations.asList()) {
       if (aggregation instanceof StringTerms) {
         for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
           FacetValue facetValue = new FacetValue(value.getKey(), value.getDocCount());
           stats.put(aggregation.getName(), facetValue);
         }
       } else if (aggregation instanceof InternalValueCount) {
         InternalValueCount count = (InternalValueCount) aggregation;
         FacetValue facetValue = new FacetValue(count.getName(), count.getValue());
         stats.put(count.getName(), facetValue);
       }
     }
   }
   return stats;
 }