# How to sort search result by group of specific field

**URL:** <https://discuss.elastic.co/t/how-to-sort-search-result-by-group-of-specific-field/54608>\
**Category:** Elasticsearch\
**Created:** [July 4, 2016, 5:48am UTC](https://discuss.elastic.co/t/how-to-sort-search-result-by-group-of-specific-field/54608 "2016-07-04T05:48:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vernomcrp](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@vernomcrp](https://discuss.elastic.co/u/vernomcrp)\
**Post date:** [July 4, 2016, 5:48am UTC](https://discuss.elastic.co/t/how-to-sort-search-result-by-group-of-specific-field/54608/1 "2016-07-04T05:48:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 4, 2016, 6:18am UTC](https://discuss.elastic.co/t/how-to-sort-search-result-by-group-of-specific-field/54608/2 "2016-07-04T06:18:41Z")

</div>

Have a look at the aggregation framework Elasticsearch provides.

Could help you here.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:38pm UTC](https://discuss.elastic.co/t/how-to-sort-search-result-by-group-of-specific-field/54608/3 "2017-07-05T22:38:39Z")

</div>


