How to use SQL version of STUFF and groupby in elastic search


(Mohit Nagpal) #1

For example assume mapping is following :

ID User Color
1 one blue
2 one black
3 two orange
4 two yellow

Needed Result is.

ID User Color
1 one blue, black
2 two orange, yellow

In case of SQL this can be done by GroupBy and STUFF.
How this can be done in ES.


(Mark Walkom) #2

If you are grouping by User then just do a terms aggregation on that - https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-aggregations-bucket-terms-aggregation.html


(Mohit Nagpal) #3

This will just give count. How to merge column values.


(Mark Walkom) #4

You'll probably need to do that externally once you have the buckets.


(Mohit Nagpal) #5

Thanks for suggestion.


(system) #6