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