# Composite aggregation total bucket count after bucket selector

**URL:** https://discuss.elastic.co/t/composite-aggregation-total-bucket-count-after-bucket-selector/364652
**Category:** Elasticsearch
**Created:** [August 9, 2024, 7:15am UTC](https://discuss.elastic.co/t/composite-aggregation-total-bucket-count-after-bucket-selector/364652 "2024-08-09T07:15:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Senol\_Kurt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/senol_kurt/32/113382_2.png) [@Senol\_Kurt](https://discuss.elastic.co/u/Senol_Kurt)
#### Post date: [August 9, 2024, 7:15am UTC](https://discuss.elastic.co/t/composite-aggregation-total-bucket-count-after-bucket-selector/364652/1 "2024-08-09T07:15:14Z")

</div>

Hi,

Elasticsearch: 8.3.3

Below i use composite aggregation, then filtered aggregation and finally bucket selector. It returns all the buckets in a paginated way. But what I need is total count of buckets, not the buckets itself. Is there a solution to this? Since the unique number of customers is too big I use composite agregation instead of normal bucket aggregation.

```auto
{
  "query": {
    "bool": {
      "filter": [
        {
          "terms": {
            "yearweek": [
              "2024-18", "2024-19", "2024-20", "2024-21", "2024-22", "2024-23",
              "2024-24", "2024-25", "2024-26", "2024-27", "2024-28", "2024-29",
              "2024-30", "2024-31"
            ]
          }
        }
      ]
    }
  },
  "aggs": {
        "customers_composite": {
          "composite": {
            "sources": [
              {"customers_agg": {"terms": {"field": "customer.keyword"}}}
            ],
            "size": 10000
          },
          "aggs": {
            "last_week_count": {
              "filter": {"term": {"yearweek": "2024-31"}}
            },
            "previous_weeks_count": {
              "filter": {
                "terms": {
                  "yearweek": [
                    "2024-18", "2024-19", "2024-20", "2024-21", "2024-22", "2024-23",
                    "2024-24", "2024-25", "2024-26", "2024-27", "2024-28", "2024-29",
                    "2024-30"
                  ]
                }
              }
            },
            "only_last_period": {
              "bucket_selector": {
                "buckets_path": {
                  "currentPeriod": "last_week_count._count",
                  "previousPeriods": "previous_weeks_count._count"
                },
                "script": "params.currentPeriod > 0 && params.previousPeriods == 0"
              }
            }
          }
        }
      }
    }

```

---

<div class="post-metadata">

### Author: ![Senol\_Kurt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/senol_kurt/32/113382_2.png) [@Senol\_Kurt](https://discuss.elastic.co/u/Senol_Kurt)
#### Post date: [December 3, 2024, 12:29pm UTC](https://discuss.elastic.co/t/composite-aggregation-total-bucket-count-after-bucket-selector/364652/2 "2024-12-03T12:29:50Z")

</div>

any response from the Elastic Team?
