Need help with a query

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]

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.