# Elastic App Search UI - Group by field

**URL:** https://discuss.elastic.co/t/elastic-app-search-ui-group-by-field/366144
**Category:** Elastic Search
**Tags:** elastic-app-search
**Created:** [September 6, 2024, 9:42am UTC](https://discuss.elastic.co/t/elastic-app-search-ui-group-by-field/366144 "2024-09-06T09:42:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![b3t](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/b3t/32/137367_2.png) [@b3t](https://discuss.elastic.co/u/b3t)
#### Post date: [September 6, 2024, 9:42am UTC](https://discuss.elastic.co/t/elastic-app-search-ui-group-by-field/366144/1 "2024-09-06T09:42:23Z")

</div>

Hi everyone,

I'm working on implementing a **group-by functionality** in my React app using **Elastic's search-ui** and running into some roadblocks. I've tried multiple approaches to achieve grouping and aggregations, but none have worked as expected.

1. I tried using the **`group` property** in the search query. While this does group the results, it only **returns between 1 to 10 documents** per group, which isn’t sufficient for my use case where **I need all items associated with each group.**

2. I also tried to pass the **`aggs` and `aggregations` property** but this ended up in an Error: **[400] Options contains invalid key: aggs**

At this point, it seems like search-ui's App Search integration may not fully support the advanced grouping and aggregation features I need, but I’m hoping there might be a **workaround**.

Any advice would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)
#### Post date: [September 6, 2024, 9:48am UTC](https://discuss.elastic.co/t/elastic-app-search-ui-group-by-field/366144/2 "2024-09-06T09:48:11Z")

</div>

Do you have any UI mockups of what you're trying to achieve?

When you mention grouping, i think of product carousels [Product Carousels | Documentation](https://www.elastic.co/docs/current/search-ui/solutions/ecommerce/carousel)

Joe

---

<div class="post-metadata">

### Author: ![b3t](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/b3t/32/137367_2.png) [@b3t](https://discuss.elastic.co/u/b3t)
#### Post date: [September 6, 2024, 10:01am UTC](https://discuss.elastic.co/t/elastic-app-search-ui-group-by-field/366144/3 "2024-09-06T10:01:10Z")

</div>

> [@joemcelroy](#):
>
> product

When I refer to **grouping** , I mean organizing the search results by a shared attribute, such as a **tag** or **category**. The idea is to have results displayed in distinct sections based on that shared field. Each section (or group) would have a heading corresponding to the tag/category (e.g., "Tag 1", "Tag 2"), and underneath, all the related items would be listed.

### Grouping Example:

1. **Group by a Field** : Results are grouped by a field like `tags` or `category`. Each group contains all items that share that specific field value.
2. **Visual Layout** : The results are displayed in different sections, each labeled with the group's field (e.g., "Tag 1" at the top of one section, "Tag 2" at the top of another).
3. **Clear Separation of Groups** : Each group is clearly separated from the others, making it easy to navigate through the data.

### The Core Issue:

My problem isn’t how to implement this in **React** (which is straightforward). The main challenge is **how to get the data grouped directly from Elastic App Search**. App Search doesn't seem to support **grouping or aggregations** in the same way as Elasticsearch’s native queries do. For instance, using the `group` property in App Search only returns 1 to 10 items per group, which isn't sufficient for my needs.

I’m looking for a way to get all the items related to each group from **Elastic App Search** , but without running into these limitations. Do you have any suggestions on how to proceed with grouping in App Search, or would a switch to native Elasticsearch be required to achieve this functionality?

---

<div class="post-metadata">

### Author: ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)
#### Post date: [September 6, 2024, 2:02pm UTC](https://discuss.elastic.co/t/elastic-app-search-ui-group-by-field/366144/4 "2024-09-06T14:02:04Z")

</div>

Thanks that makes more sense of what you're trying to achieve.

Theres two options with app search:

- Grouping API [Search API group | App Search documentation [8.15] | Elastic](https://www.elastic.co/guide/en/app-search/current/grouping.html)
- Performing two separate queries: One to get facets for a particular field and then performing a search for each of the facet values.

Joe

---

<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: [October 4, 2024, 2:02pm UTC](https://discuss.elastic.co/t/elastic-app-search-ui-group-by-field/366144/5 "2024-10-04T14:02:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
