SQL like Group by in Elasticsearch

May be I don't understand so an example would help.
Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

But may be others have an idea.