# Using "partial" terms aggregation

**URL:** <https://discuss.elastic.co/t/using-partial-terms-aggregation/251347>\
**Category:** Elasticsearch\
**Created:** [October 7, 2020, 10:24pm UTC](https://discuss.elastic.co/t/using-partial-terms-aggregation/251347 "2020-10-07T22:24:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![angauber](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@angauber](https://discuss.elastic.co/u/angauber)\
**Post date:** [October 7, 2020, 10:24pm UTC](https://discuss.elastic.co/t/using-partial-terms-aggregation/251347/1 "2020-10-07T22:24:06Z")

</div>

I have populate a test index with the following data:

```
/test/_bulk
{"index": {}}
{"types": [1, 2, 4]}
{"index": {}}
{"types": [3]}
{"index": {}}
{"types": [1, 4]}

```

On that index I'm trying to a build a query where I filter on the `types` field while matching the `name` field with a query string.

The query I built works fine but I'd like to use terms aggregation on the `types` field to display the result count per `type` on a facet.

When using aggregation like so:

```
"aggs": {
    "types_count": {
        "terms": {
            "field": "types"
        }
    }
}

```

My problem is that the bucket I get only contains the types that where present in the filter of my query.

I searched for `Partial aggregation` But only found `Global aggregation` that exclude the whole query from the bucket content.

Is there any way to exclude a part of a query to build the aggregation bucket or will I need to build a second query that does not use filtering ?

Thanks

---

<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 4, 2020, 10:24pm UTC](https://discuss.elastic.co/t/using-partial-terms-aggregation/251347/2 "2020-11-04T22:24:23Z")

</div>

Closed on November 4, 2020, 10:24pm UTC

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