Painless flatten


(Hu Jun) #1

Working on a watcher, similar to Flatten nested aggregation

but as I am still using ES 5.5, no composition agg avaiable :frowning:

in my query, i have a cascade of aggregations:

{
    aggs: {
        A 
        aggs: {
             B
               aggs: {
                     C
               
               }
        }
    }
}

In my watcher transform, I want to flatten the result to a list in case that buckets is not empty:

[ { A1.key, B1.key, C1.key },
  { A1.key, B1.key, C2.key },
  { A2.key, B2.key, C1.key } ... ]

want to find an easy way instead of loop the for, any suggestion, thank you in advance.


(Hu Jun) #2

Finally, found a solution based on flatMap and map

aggs.stream().flatMap(a -> a.stream().flatMap( b->b.stream().map( c-> -> ['A': a.key, 'B': b.key, 'C': c.key ] ) ) ).collect(Collectors.toList())


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.