# Aggregations : OR filter for terms within a specific field

**URL:** <https://discuss.elastic.co/t/aggregations-or-filter-for-terms-within-a-specific-field/39897>\
**Category:** Elasticsearch\
**Created:** [January 22, 2016, 3:31pm UTC](https://discuss.elastic.co/t/aggregations-or-filter-for-terms-within-a-specific-field/39897 "2016-01-22T15:31:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemed](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@hemed](https://discuss.elastic.co/u/hemed)\
**Post date:** [January 22, 2016, 3:31pm UTC](https://discuss.elastic.co/t/aggregations-or-filter-for-terms-within-a-specific-field/39897/1 "2016-01-22T15:31:07Z")

</div>

Hi,

Here I am trying to build an OR filter for field "assignee" using terms aggregations. Please consider the following query, the results for this query are in Case 2 below :-

"query": {

```
"filtered": {
    "query": {
        "query_string": {
            "query": "*"
        }
    },
    "filter": {
        "bool": {
            "must": {
                "term": {
                    "assignee": ["Eddie"]
                }
            }
        }
    }
}},"aggregations": {

"assignee": {
    "terms": {
        "field": "assignee",
        "size": 10,
        "min_doc_count": 0
    }
}, "status": {
    "terms": {
        "field": "status",
        "size": 10,
        "min_doc_count": 0
    }
}

```

}

Now when I run this query, all the terms in the field "assignee" are getting 0 count, except "Diddie" (See case 2)

But since it's an OR filter in this particular field "assignee", I don't want to update the count for any term in this field, so that a user may see the full list. But I want the selection to affect other aggregations that have not been selected yet. Any idea on how I can achieve this (Case 3 below)?

==EDIT==  
See Case 3, selected term is "Eddie" but all the terms under "Assignee" are not updated (OR filter) but other terms in other aggregations (see "Status" ) are updated accordingly.

Case 1 (Original, No filters):`Assignee : ( ) Eddie: 2 ( ) Diddie: 2 ( ) Joe: 1 Status: ( ) Sent: 3 ( ) Draft: 2`

Case 2 (filter=Eddie):`Assignee: (x) Eddie: 2 ( ) Diddie: 0 ( ) Joe: 0 Status: ( ) Sent: 1 ( ) Draft: 1`

Case 3 (filter=Eddie):`Assignee: (x) Eddie: 2 ( ) Diddie: 2 ( ) Joe: 1 Status: ( ) Sent: 1 ( ) Draft: 1`

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [January 25, 2016, 8:15pm UTC](https://discuss.elastic.co/t/aggregations-or-filter-for-terms-within-a-specific-field/39897/2 "2016-01-25T20:15:47Z")

</div>

I suspect what you are after is either `post_filter` or `global` aggregations?

---

<div class="post-metadata">

**Author:** ![hemed](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@hemed](https://discuss.elastic.co/u/hemed)\
**Post date:** [January 26, 2016, 10:50am UTC](https://discuss.elastic.co/t/aggregations-or-filter-for-terms-within-a-specific-field/39897/3 "2016-01-26T10:50:45Z")

</div>

I have tried but I could not get it working. I have updated my question with examples, please have a look.

---

<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 5, 2017, 11:21pm UTC](https://discuss.elastic.co/t/aggregations-or-filter-for-terms-within-a-specific-field/39897/4 "2017-07-05T23:21:36Z")

</div>


