|
24 | 24 | import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
25 | 25 | import org.elasticsearch.search.aggregations.bucket.range.Range;
|
26 | 26 | import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
27 |
| -import org.elasticsearch.search.aggregations.metrics.stats.Stats; |
| 27 | +import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; |
| 28 | +import org.elasticsearch.search.aggregations.metrics.sum.Sum; |
| 29 | +import org.joda.time.DateTime; |
28 | 30 | import org.springframework.data.domain.PageImpl;
|
29 | 31 | import org.springframework.data.domain.Pageable;
|
30 | 32 | import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
| 33 | +import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; |
31 | 34 | import org.springframework.data.elasticsearch.core.facet.FacetResult;
|
| 35 | +import org.springframework.data.elasticsearch.core.facet.request.RangeFacetRequest; |
32 | 36 | import org.springframework.data.elasticsearch.core.facet.result.*;
|
33 | 37 |
|
34 | 38 | /**
|
@@ -88,24 +92,35 @@ private void processAggregations() {
|
88 | 92 | for (Terms.Bucket t : ((Terms) agg).getBuckets()) {
|
89 | 93 | terms.add(new Term(t.getKeyAsString(), t.getDocCount()));
|
90 | 94 | }
|
91 |
| - addFacet(new TermResult(agg.getName(), terms, terms.size(), ((Terms) agg).getSumOfOtherDocCounts(), -1)); |
| 95 | + addFacet(new TermResult(agg.getName(), terms, terms.size(), ((Terms) agg).getSumOfOtherDocCounts(), 0)); |
92 | 96 | }
|
93 | 97 | if (agg instanceof Range) {
|
94 | 98 | List<? extends Range.Bucket> buckets = ((Range) agg).getBuckets();
|
95 | 99 | List<org.springframework.data.elasticsearch.core.facet.result.Range> ranges = new ArrayList<org.springframework.data.elasticsearch.core.facet.result.Range>();
|
96 | 100 | for (Range.Bucket b : buckets) {
|
97 |
| - ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), 0, 0, 0, 0)); |
| 101 | + ExtendedStats rStats = (ExtendedStats) b.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS); |
| 102 | + if (rStats != null) { |
| 103 | + Sum sum = (Sum) b.getAggregations().get(RangeFacetRequest.RANGE_INTERNAL_SUM); |
| 104 | + ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), sum != null ? sum.getValue() : rStats.getSum(), rStats.getCount(), rStats.getMin(), rStats.getMax())); |
| 105 | + } else { |
| 106 | + ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), 0, 0, 0, 0)); |
| 107 | + } |
98 | 108 | }
|
99 | 109 | addFacet(new RangeResult(agg.getName(), ranges));
|
100 | 110 | }
|
101 |
| - if (agg instanceof Stats) { |
102 |
| - Stats stats = (Stats) agg; |
103 |
| - addFacet(new StatisticalResult(agg.getName(), stats.getCount(), stats.getMax(), stats.getMin(), stats.getAvg(), -1, -1, stats.getSum(), -1)); |
| 111 | + if (agg instanceof ExtendedStats) { |
| 112 | + ExtendedStats stats = (ExtendedStats) agg; |
| 113 | + addFacet(new StatisticalResult(agg.getName(), stats.getCount(), stats.getMax(), stats.getMin(), stats.getAvg(), stats.getStdDeviation(), stats.getSumOfSquares(), stats.getSum(), stats.getVariance())); |
104 | 114 | }
|
105 | 115 | if (agg instanceof Histogram) {
|
106 | 116 | List<IntervalUnit> intervals = new ArrayList<IntervalUnit>();
|
107 | 117 | for (Histogram.Bucket h : ((Histogram) agg).getBuckets()) {
|
108 |
| - new IntervalUnit((Long) h.getKey(), h.getDocCount(), h.getDocCount(), -1, -1, -1, -1); |
| 118 | + ExtendedStats hStats = (ExtendedStats) h.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS); |
| 119 | + if (hStats != null) { |
| 120 | + intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), hStats.getSum(), hStats.getAvg(), hStats.getMin(), hStats.getMax())); |
| 121 | + } else { |
| 122 | + intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), 0, 0, 0, 0)); |
| 123 | + } |
109 | 124 | }
|
110 | 125 | addFacet(new HistogramResult(agg.getName(), intervals));
|
111 | 126 | }
|
|
0 commit comments