# Need help with a query

**URL:** <https://forum.opensearch.org/t/need-help-with-a-query/15022>\
**Category:** OpenSearch\
**Tags:** query-workbench\
**Created:** [July 9, 2023, 3:02pm UTC](https://forum.opensearch.org/t/need-help-with-a-query/15022 "2023-07-09T15:02:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![localforecast391](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@localforecast391](https://forum.opensearch.org/u/localforecast391)\
**Post date:** [July 9, 2023, 3:02pm UTC](https://forum.opensearch.org/t/need-help-with-a-query/15022/1 "2023-07-09T15:02:32Z")

</div>

**Describe the issue** :

I need help with a query to group the results.

GET user\_info,user\_auth\_cards\_info/\_search  
{  
“from”: 0,  
“size”: 20,  
“query”: {  
“bool”: {  
“filter”: [  
{  
“match”: {  
“e\_name.autocomplete”: {  
“query”: “tes”  
}  
}  
}  
]  
}  
}  
}

I want to group the results so that we have three different arrays where the results start with “tes” and then contains “tes” and then everything else

so ie

[tes,test, test123]  
[abtes, btest]  
[hello, etc]

---

<div class="post-metadata">

**Author:** ![radu.gheorghe](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/radu.gheorghe/32/3516_2.png) [@radu.gheorghe](https://forum.opensearch.org/u/radu.gheorghe)\
**Post date:** [July 13, 2023, 4:09pm UTC](https://forum.opensearch.org/t/need-help-with-a-query/15022/2 "2023-07-13T16:09:15Z")

</div>

I think there are two ways of doing this:

1. Run three separate queries or do a multi-search with one query for each.
2. Do a filters aggregation (one filter for each case) and display results via the top\_hits aggregation.

The first variant is faster and easier to parallelize, but with the second one you may be able to do other stuff as you’re processing these results.
