@@ -166,24 +166,28 @@ trait ElasticConversion {
166166 val ret = parseAggregations(aggs, ListMap .empty, fieldAliases, aggregations)
167167 val groupedRows : Map [String , Seq [ListMap [String , Any ]]] =
168168 ret.groupBy(_.getOrElse(" bucket_root" , " " ).toString)
169- groupedRows.values.foldLeft(Seq (ListMap .empty[String , Any ])) { (acc, group) =>
170- for {
171- accMap <- acc
172- groupMap <- group
173- } yield accMap ++ groupMap
174- }
169+ groupedRows.values
170+ .foldLeft(Seq (ListMap .empty[String , Any ])) { (acc, group) =>
171+ for {
172+ accMap <- acc
173+ groupMap <- group
174+ } yield accMap ++ groupMap
175+ }
176+ .map(_ - " bucket_root" )
175177
176178 case (Some (hits), Some (aggs)) if hits.isEmpty =>
177179 // Case 3 : aggregations with no hits
178180 val ret = parseAggregations(aggs, ListMap .empty, fieldAliases, aggregations)
179181 val groupedRows : Map [String , Seq [ListMap [String , Any ]]] =
180182 ret.groupBy(_.getOrElse(" bucket_root" , " " ).toString)
181- groupedRows.values.foldLeft(Seq (ListMap .empty[String , Any ])) { (acc, group) =>
182- for {
183- accMap <- acc
184- groupMap <- group
185- } yield accMap ++ groupMap
186- }
183+ groupedRows.values
184+ .foldLeft(Seq (ListMap .empty[String , Any ])) { (acc, group) =>
185+ for {
186+ accMap <- acc
187+ groupMap <- group
188+ } yield accMap ++ groupMap
189+ }
190+ .map(_ - " bucket_root" )
187191
188192 case (Some (hits), Some (aggs)) if hits.nonEmpty =>
189193 // Case 4 : Hits + global aggregations + top_hits aggregations
@@ -204,7 +208,9 @@ trait ElasticConversion {
204208 }
205209
206210 // Normalize all rows at the end, after all transformations (flattening, aggregation merging)
207- rows.map(row => normalizeRow(row, fields))
211+ // Filter out "*" from fields — it is an artifact of COUNT(*) and not a real column
212+ val effectiveFields = fields.filterNot(_ == " *" )
213+ rows.map(row => normalizeRow(row, effectiveFields))
208214 }
209215
210216 def findKeyValue (path : String , map : Map [String , Any ]): Option [Any ] = {
0 commit comments