# Show aggregations of same category after filter

**URL:** <https://discuss.elastic.co/t/show-aggregations-of-same-category-after-filter/318055>\
**Category:** Elasticsearch\
**Created:** [November 2, 2022, 9:21pm UTC](https://discuss.elastic.co/t/show-aggregations-of-same-category-after-filter/318055 "2022-11-02T21:21:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Valek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_valek/32/112868_2.png) [@Peter\_Valek](https://discuss.elastic.co/u/Peter_Valek)\
**Post date:** [November 2, 2022, 9:21pm UTC](https://discuss.elastic.co/t/show-aggregations-of-same-category-after-filter/318055/1 "2022-11-02T21:21:35Z")

</div>

Hello everyone !

I would like to create filter and aggregations after filter for procuts in Elasticsearch. I am having base aggregations for all products:

```auto
"size": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 87,
        "buckets": [
            {
                "key": "6",
                "doc_count": 10
            },
            {
                "key": "5,5",
                "doc_count": 10
            }
        ]
    }
},
"brand": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 87,
        "buckets": [
            {
                "key": "Apple",
                "doc_count": 20
            },
            {
                "key": "Samsung",
                "doc_count": 10
            },
            {
                "key": "Xiaomi",
                "doc_count": 48
            },
            {
                "key": "Huawei",
                "doc_count": 33
            }
        ]
    }
}

```

After I make query for one of those **brands** and size like:

```auto
query": {
      "bool": {
        "filter": [
          "term": {
            "brand": "Samsung"
          },
          "term": {
            "size": "6"
          }
        ]
      }
    }

```

I am getting back aggregations only for filtered **brand** Samsung.

Actual Result

```auto
"size": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 87,
        "buckets": [
            {
                "key": "6",
                "doc_count": 3
            },
            {
                "key": "5,5",
                "doc_count": 2
            }
        ]
    }
  },
  "brand": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 87,
          "buckets": [
              {
                  "key": "Samsung",
                  "doc_count": 5
              },
          ]
      }
  }

```

But i still want to see in aggregations for all others **brands** with filtered **size**.  
Something like:

```auto
"size": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 87,
        "buckets": [
            {
                "key": "6",
                "doc_count": 5
            },
            {
                "key": "5,5",
                "doc_count": 5
            }
        ]
    }
  },
  "brand": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 87,
          "buckets": [
              {
                  "key": "Apple",
                  "doc_count": 10
              },
              {
                  "key": "Samsung",
                  "doc_count": 5
              },
          ]
      }
  }

```

Is this possible with ES?

Thank you so much for all answers.

---

<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:** [November 30, 2022, 9:22pm UTC](https://discuss.elastic.co/t/show-aggregations-of-same-category-after-filter/318055/2 "2022-11-30T21:22:28Z")

</div>

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