14
14
import org .elasticsearch .search .aggregations .bucket .geogrid .GeoHashGrid ;
15
15
import org .elasticsearch .search .aggregations .metrics .MetricsAggregator ;
16
16
import org .elasticsearch .search .aggregations .metrics .NumericMetricsAggregation ;
17
+ import org .elasticsearch .search .aggregations .metrics .geobounds .GeoBounds ;
17
18
import org .elasticsearch .search .aggregations .metrics .percentiles .Percentile ;
18
19
import org .elasticsearch .search .aggregations .metrics .percentiles .Percentiles ;
19
20
import org .elasticsearch .search .aggregations .metrics .scripted .ScriptedMetric ;
20
21
import org .elasticsearch .search .aggregations .metrics .stats .Stats ;
21
22
import org .elasticsearch .search .aggregations .metrics .stats .extended .ExtendedStats ;
23
+ import org .elasticsearch .search .aggregations .metrics .tophits .TopHits ;
22
24
import org .nlpcn .es4sql .Util ;
23
25
24
26
import java .util .*;
@@ -59,8 +61,6 @@ public CSVResult extractResults(Object queryResult, boolean flat, String separat
59
61
//todo: need to handle more options for aggregations:
60
62
//Aggregations that inhrit from base
61
63
//ScriptedMetric
62
- //TopHits
63
- //GeoBounds
64
64
65
65
return new CSVResult (headers ,csvLines );
66
66
@@ -82,13 +82,22 @@ private void handleAggregations(Aggregations aggregations, List<String> headers
82
82
//we want to skip singleBucketAggregations (nested,reverse_nested,filters)
83
83
if (aggregation instanceof SingleBucketAggregation ){
84
84
Aggregations singleBucketAggs = ((SingleBucketAggregation ) aggregation ).getAggregations ();
85
- handleAggregations (singleBucketAggs ,headers ,lines );
85
+ handleAggregations (singleBucketAggs , headers , lines );
86
86
return ;
87
87
}
88
88
if (aggregation instanceof NumericMetricsAggregation ){
89
- handleNumericMetricAggregation (headers ,lines .get (currentLineIndex ),aggregation );
89
+ handleNumericMetricAggregation (headers , lines .get (currentLineIndex ), aggregation );
90
90
return ;
91
91
}
92
+ if (aggregation instanceof GeoBounds ){
93
+ handleGeoBoundsAggregation (headers , lines , (GeoBounds ) aggregation );
94
+ return ;
95
+ }
96
+ if (aggregation instanceof TopHits ){
97
+ //todo: handle this . it returns hits... maby back to normal?
98
+ //todo: read about this usages
99
+ // TopHits topHitsAggregation = (TopHits) aggregation;
100
+ }
92
101
if (aggregation instanceof MultiBucketsAggregation ){
93
102
MultiBucketsAggregation bucketsAggregation = (MultiBucketsAggregation ) aggregation ;
94
103
String name = bucketsAggregation .getName ();
@@ -123,6 +132,20 @@ private void handleAggregations(Aggregations aggregations, List<String> headers
123
132
124
133
}
125
134
135
+ private void handleGeoBoundsAggregation (List <String > headers , List <List <String >> lines , GeoBounds geoBoundsAggregation ) {
136
+ String geoBoundAggName = geoBoundsAggregation .getName ();
137
+ headers .add (geoBoundAggName +".topLeft.lon" );
138
+ headers .add (geoBoundAggName +".topLeft.lat" );
139
+ headers .add (geoBoundAggName +".bottomRight.lon" );
140
+ headers .add (geoBoundAggName +".bottomRight.lat" );
141
+ List <String > line = lines .get (this .currentLineIndex );
142
+ line .add (String .valueOf (geoBoundsAggregation .topLeft ().getLon ()));
143
+ line .add (String .valueOf (geoBoundsAggregation .topLeft ().getLat ()));
144
+ line .add (String .valueOf (geoBoundsAggregation .bottomRight ().getLon ()));
145
+ line .add (String .valueOf (geoBoundsAggregation .bottomRight ().getLat ()));
146
+ lines .add (line );
147
+ }
148
+
126
149
private List <String > fillHeaderAndCreateLineForNumericAggregations (Aggregations aggregations , List <String > header ) throws CsvExtractorException {
127
150
List <String > line = new ArrayList <>();
128
151
List <Aggregation > aggregationList = aggregations .asList ();
@@ -241,7 +264,7 @@ private List<String> createHeadersAndFillDocsMap(boolean flat, SearchHit[] hits,
241
264
}
242
265
mergeHeaders (csvHeaders , doc , flat );
243
266
if (this .includeScore ){
244
- doc .put ("_score" ,hit .score ());
267
+ doc .put ("_score" , hit .score ());
245
268
}
246
269
if (this .includeType ){
247
270
doc .put ("_type" ,hit .type ());
0 commit comments