How to sort search result by group of specific field

How to get sorted result like this. I thinking about using 'Having' and 'Order by' in sql, But not sure if I can do it in ES.

item-1, score 10,group A
item-2, score 9,group A
item-3, score 8.5,group A
item-4, score 12,group B
item-5, score 9.6, group B
item-6, score 6.4, group B
item-7, score 10, no group
item-8, score 20, no group

Have a look at the aggregation framework Elasticsearch provides.

Could help you here.