# Filtering on aggregations

**URL:** <https://discuss.elastic.co/t/filtering-on-aggregations/362130>\
**Category:** Elasticsearch\
**Created:** [June 27, 2024, 4:18am UTC](https://discuss.elastic.co/t/filtering-on-aggregations/362130 "2024-06-27T04:18:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navnath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navnath/32/135617_2.png) [@Navnath](https://discuss.elastic.co/u/Navnath)\
**Post date:** [June 27, 2024, 4:18am UTC](https://discuss.elastic.co/t/filtering-on-aggregations/362130/1 "2024-06-27T04:18:23Z")

</div>

Hello,

I am doing a search operation to get some product results with their associated aggregations.  
**So , here, aggregations are by products of the search result**  
When I fetch this result, I ask for only 100 aggregations (this is just for our UI requirement)  
On UI side, when I click on "next" button, I get 200 aggregations and so on.

Now, my requirement is to filter or search through the aggregations themselves.  
For example, if I have 1000 aggregations on the index and If I ask for aggregations with substring "xyz", it should return all of the matching aggregations.

So,

1. First, I need to perform search to get products. Because, I want to show them on UI. Along with products, I get their associated aggregations.
2. Now, I want to search through **ALL aggregations on the index** (not just 100 or 200 but search through all of them) based on my search string.

Do we have any solution for this scenario?  
Thank you in advance for your answer.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 27, 2024, 10:52am UTC](https://discuss.elastic.co/t/filtering-on-aggregations/362130/2 "2024-06-27T10:52:18Z")

</div>

Hi @Navnath,

Welcome to the community! Can you share the aggregation you are running? I would have thought adding your query to the aggregation request would be the best way to go, similar to the below:

```auto
POST kibana_sample_data_flights/_search
{
  "query": {
    "range": {
      "timestamp": {
        "gte": "now-7d"
      }
    }
  },
  "aggs": {
    "destinations": {
      "terms": { "field": "DestCityName" },
      "aggs": {
        "carrier_buckets": {
          "terms": {
            "field": "Carrier"
          }
        }
      }
    }
  },
  "size": 0
}

```

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Navnath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navnath/32/135617_2.png) [@Navnath](https://discuss.elastic.co/u/Navnath)\
**Post date:** [July 24, 2024, 5:51am UTC](https://discuss.elastic.co/t/filtering-on-aggregations/362130/3 "2024-07-24T05:51:01Z")

</div>

Thank @carly.richmond for your answer. 🙂
