# Multiple filters on Filter Aggregation

**URL:** https://discuss.elastic.co/t/multiple-filters-on-filter-aggregation/141613
**Category:** Elasticsearch
**Created:** [July 25, 2018, 3:33pm UTC](https://discuss.elastic.co/t/multiple-filters-on-filter-aggregation/141613 "2018-07-25T15:33:22Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![zivari](https://avatars.discourse-cdn.com/v4/letter/z/9e8a1a/32.png) [@zivari](https://discuss.elastic.co/u/zivari)
#### Post date: [July 25, 2018, 3:33pm UTC](https://discuss.elastic.co/t/multiple-filters-on-filter-aggregation/141613/1 "2018-07-25T15:33:22Z")

</div>

Hey,

Using ElasticSearch aggregation to aggregate data on my documents.  
so the aggregation request looks something like this

```
 {  
   "query":{  
      "bool":{  
         "filter":[  
            {  
               "terms":{  
                  "status":[  
                     "active",
                     "deleted"
                  ]
               }
            },
            {  
               "terms":{  
                  "address_ids":[  
                     4078,
                     4080
                  ]
               }
            }
         ]
      }
   },
   "aggregations":{  
      "neighbourhoods":{  
         "terms":{  
            "field":"neighbourhoods",
            "size":100
         }
      },
      "budgets_stats":{  
         "filter":{  
            "range":{  
               "budget":{  
                  "lt":100000
               }
            }
         },
         "aggregations":{  
            "budget":{  
               "stats":{  
                  "field":"budget"
               }
            }
         }
      }
   }
}

```

i want to filter out documents that match \*\* budget lower than 100000 \*\* and add more filters to that specific aggregation.  
I cant add it to the query clause, because i have other aggregation in which i dont want these budget filters to apply.

I cant use the filters aggregation either because it creates a different bucket for each filter - instead of 1 bucket with all filters applied to it.

How can create a filter aggregation with more than 1 filter? lets say the other condition should be  
"budgets\_stats":{  
"filter":  
{  
"range":{  
"vip\_budget":{  
"gt":500  
}  
}  
}  
}

i have tried using Array but its not working.

`filter: [{:range=>{:budget=>{:lt=>100000}}}, {:range=>{:vip_budget=>{:gt=>500}}}]`

getting this error (using rails gems)

Elasticsearch::Transport::Transport::Errors::BadRequest Exception: [400] {"error":{"root\_cause":[{"type":"parsing\_exception","reason":"**Expected [START\_OBJECT] under [filter], but got a [START\_ARRAY] in [budgets\_stats]","line":1,"col":233}]**,"type":"parsing\_exception","reason":"Expected [START\_OBJECT] under [filter], but got a [START\_ARRAY] in [budgets\_stats]","line":1,"col":233},"status":400}

Is this even possible? couldn't find a reference in the documentation of elastic / rails gems for elastic

Will appreciate any help,

Thanks

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [July 25, 2018, 3:40pm UTC](https://discuss.elastic.co/t/multiple-filters-on-filter-aggregation/141613/2 "2018-07-25T15:40:12Z")

</div>

> [@zivari](#):
>
> How can create a filter aggregation with more than 1 filter?

You can combine filter criteria using the `bool` tag, much like you can query clauses.

---

<div class="post-metadata">

### Author: ![zivari](https://avatars.discourse-cdn.com/v4/letter/z/9e8a1a/32.png) [@zivari](https://discuss.elastic.co/u/zivari)
#### Post date: [July 25, 2018, 4:01pm UTC](https://discuss.elastic.co/t/multiple-filters-on-filter-aggregation/141613/3 "2018-07-25T16:01:40Z")

</div>

can you show me how the query should look like?

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [July 25, 2018, 4:02pm UTC](https://discuss.elastic.co/t/multiple-filters-on-filter-aggregation/141613/4 "2018-07-25T16:02:48Z")

</div>

Here's the [bool docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)

---

<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: [August 22, 2018, 4:02pm UTC](https://discuss.elastic.co/t/multiple-filters-on-filter-aggregation/141613/5 "2018-08-22T16:02:56Z")

</div>

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