# Aggregations & or query

**URL:** <https://discuss.elastic.co/t/aggregations-or-query/237784>\
**Category:** Elasticsearch\
**Created:** [June 19, 2020, 9:57am UTC](https://discuss.elastic.co/t/aggregations-or-query/237784 "2020-06-19T09:57:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbu](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gbu](https://discuss.elastic.co/u/gbu)\
**Post date:** [June 19, 2020, 9:57am UTC](https://discuss.elastic.co/t/aggregations-or-query/237784/1 "2020-06-19T09:57:40Z")

</div>

Hi,

```auto
    { 'id': 1, 'productType': 'a'}
    { 'id': 2, 'productType': 'b'}
    { 'id': 3, 'productType': 'c'}

```

we are doing a query with aggregations like

```auto
    {
        "aggs": {
            "productType": {
                "terms": {"field": "productType"}
            }
        }
    }

```

will deliver a, b, c as buckets.

if i add should block in the query with term query for 'productType' : 'a', i only have 'a' in the aggregations left.

but the aggregation is afaik unaware of the query, so is always assuming a drill down  
(so also won't offer alternatives, for the current selection).

a) is there a way to also get 'b' and 'c' back? considering i want to combine them in an 'or' query?  
b) is there a way to als get 'b' and 'c' back as an replacement for my current filter condition?

Thanks, Georg

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [June 19, 2020, 5:27pm UTC](https://discuss.elastic.co/t/aggregations-or-query/237784/2 "2020-06-19T17:27:07Z")

</div>

You need the `global` aggregator to get the others back. Without it the aggregations are indeed aware of the query.

---

<div class="post-metadata">

**Author:** ![gbu](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gbu](https://discuss.elastic.co/u/gbu)\
**Post date:** [June 22, 2020, 9:01am UTC](https://discuss.elastic.co/t/aggregations-or-query/237784/3 "2020-06-22T09:01:17Z")

</div>

thanks together with `filter` it did the trick

---

<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:** [July 20, 2020, 9:01am UTC](https://discuss.elastic.co/t/aggregations-or-query/237784/4 "2020-07-20T09:01:18Z")

</div>

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