# 1 aggregate bucket with multiple filters

**URL:** https://discuss.elastic.co/t/1-aggregate-bucket-with-multiple-filters/128936
**Category:** Elasticsearch
**Created:** [April 20, 2018, 9:03pm UTC](https://discuss.elastic.co/t/1-aggregate-bucket-with-multiple-filters/128936 "2018-04-20T21:03:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Vijay\_arora1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijay_arora1/32/13789_2.png) [@Vijay\_arora1](https://discuss.elastic.co/u/Vijay_arora1)
#### Post date: [April 20, 2018, 9:03pm UTC](https://discuss.elastic.co/t/1-aggregate-bucket-with-multiple-filters/128936/1 "2018-04-20T21:03:25Z")

</div>

I have a nested collection under the root documents, where I am trying to get a single aggregate value\_count based on multiple aggregate filters.  
For Example: I need count of address ids where city is LA or San Diego and State is CA

The Filter Aggregation allows me to put only 1 filter condition, and does not like an array of filters,  
Then i looked at the filters, which allows me to add multiple filters, but gives a bucket for associated filter.

> Blockquote  
> "\_f113-c0-test\_aggregate": {  
> "nested": {  
> "path": "test\_addresses"  
> },  
> "aggs": {  
> "\_f113-c0-test\_aggregate": {  
> "filters": {  
> "filters": [  
> {  
> "terms": { "test\_addresses.state": ["CA"] }  
> },  
> {  
> "terms": {  
> "test\_addresses.city": ["Los Angeles" , "San Diege"]  
> }  
> }  
> ]  
> },  
> "aggs": {  
> "\_f113-c0-test\_aggregate": {  
> "value\_count": {  
> "field": "test\_addresses.AddressId"  
> }  
> }  
> }  
> }  
> }  
> }

> Blockquote

How can i get 1 aggregate count with multiple filters applied to it.

Thanks

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [April 23, 2018, 6:00pm UTC](https://discuss.elastic.co/t/1-aggregate-bucket-with-multiple-filters/128936/2 "2018-04-23T18:00:57Z")

</div>

You can use a `bool` query and multiple `terms` queries inside the bool's `must` section. Then throw that whole thing inside the `filter` aggregation 🙂

---

<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: [May 21, 2018, 6:00pm UTC](https://discuss.elastic.co/t/1-aggregate-bucket-with-multiple-filters/128936/3 "2018-05-21T18:00:57Z")

</div>

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