# Group Query with Top hits - Scope for Performance improvement

**URL:** <https://discuss.elastic.co/t/group-query-with-top-hits-scope-for-performance-improvement/23930>\
**Category:** Elasticsearch\
**Created:** [June 18, 2015, 4:06pm UTC](https://discuss.elastic.co/t/group-query-with-top-hits-scope-for-performance-improvement/23930 "2015-06-18T16:06:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PradeepKS](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@PradeepKS](https://discuss.elastic.co/u/PradeepKS)\
**Post date:** [June 18, 2015, 4:06pm UTC](https://discuss.elastic.co/t/group-query-with-top-hits-scope-for-performance-improvement/23930/1 "2015-06-18T16:06:29Z")

</div>

Hi,

I have written the following group query which groups and sorts based on Top-hits. But this seems to be lower performance compared to SOLRCloud. Is there any scope for improvising the same..? advice

{  
"size" : 0,  
"query" : {  
"bool" : {  
"must" : {  
"match" : { "bookType" : "Horror" }  
},  
"must" : {  
"match" : { "sections" : "5" }  
},  
"must" : {  
"range" : {  
"publishedDate" : {  
"gte": "now+6h"  
}  
}  
}  
}  
},  
"aggs": {  
"grp\_by\_published\_date": {  
"terms": {  
"field": "publishedDate"  
},  
"aggs": {  
"grp\_by\_published\_date\_hits": {  
"top\_hits": {  
"sort": [  
{  
"publishedDate": {  
"order": "asc"  
}  
}  
],  
"\_source": {  
"include": [  
"author","pages","publisedDate","reviewLink"  
]  
},  
"size" : 1  
}  
}  
}  
}  
}  
}

Thanks,  
Pradeep

---

<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 6, 2017, 12:06am UTC](https://discuss.elastic.co/t/group-query-with-top-hits-scope-for-performance-improvement/23930/2 "2017-07-06T00:06:41Z")

</div>

Closed on July 6, 2017, 12:06am UTC


