How to group results in OpenSearch?

As a newcomer to OpenSearch, I am exploring it for my business needs. Specifically, I am searching for a search engine that enables grouping of search results based on their fields (e.g. country attribute, and grouping based on which country).

I noticed that Elastic Search supports this functionality either through collapse (ref 1) or aggregations (ref 2). Thus, I am interested to learn whether OpenSearch offers a similar feature. If you could also give an example of a query accomplishing this outcome that would be great. Thank you.

ref 1: Collapse search results | Elasticsearch Guide [8.7] | Elastic ref 2: How to get latest values for each group with an Elasticsearch query?

Bonus question: for each grouping, what could be the maximum number of results shown? Would there be a way to show unlimited results?

1 Like

OpenSearch supports both collapse and aggregation, you can take a look at the documentation of terms aggregation and top hits aggregation, that can solve your problem.