# Multiple filters for facets

**URL:** <https://discuss.elastic.co/t/multiple-filters-for-facets/4290>\
**Category:** Elasticsearch\
**Created:** [April 25, 2011, 9:54pm UTC](https://discuss.elastic.co/t/multiple-filters-for-facets/4290 "2011-04-25T21:54:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jasper\_van\_Wanrooy\_C](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasper_van_wanrooy_c/32/2494_2.png) [@Jasper\_van\_Wanrooy\_C](https://discuss.elastic.co/u/Jasper_van_Wanrooy_C)\
**Post date:** [April 25, 2011, 9:54pm UTC](https://discuss.elastic.co/t/multiple-filters-for-facets/4290/1 "2011-04-25T21:54:26Z")

</div>

Hi,

I just got my data indexed and I'm able to add some facets to it. Right now I want to filter the selected values of the facets. I took a look at the filtered query, however, only one filter can be added.  
What's the best way of doing that? The query I used right now looks like this:

{  
"query":{  
"filtered":{  
"query":{  
"match\_all":{

```
        }
     },
     "filter":{
        "terms":{
           "shop.id":[
              192,
              182
           ]
        }
     }
  }

```

},  
"size":25,  
"highlight":{  
"tags\_schema":"styled",  
"fields":{  
"\_all":[

```
     ],
     "name":[

     ],
     "description":{
        "fragment_size":50
     }
  }

```

},  
"sort":{  
"price":"desc"  
},  
"facets":{  
"facet\_brand":{  
"terms":{  
"field":"brand",  
"size":10,  
"order":"count",  
"exclude":[  
""  
]  
}  
},  
"facet\_price":{  
"range":{  
"field":"price",  
"ranges":[  
{  
"from":null,  
"to":20  
},  
{  
"from":20,  
"to":100  
},  
{  
"from":100,  
"to":500  
},  
{  
"from":500,  
"to":null  
}  
]  
}  
}  
}  
}

Thanks!

Jasper

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 26, 2011, 5:48pm UTC](https://discuss.elastic.co/t/multiple-filters-for-facets/4290/2 "2011-04-26T17:48:35Z")

</div>

Even if "one" filter can be placed where a filter can be placed, there are and, or, not filters which allow to build more compound filters.

Check the filter element in search API, it is aimed specifically for facet navigation (and can work better than filtered query feature wise for this scenario): [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/filter.html).

Also, each facet can have an associated filter using the facet\_filter element: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/) (check Filter at the end).

-shay.banon  
On Tuesday, April 26, 2011 at 12:54 AM, Jasper van Wanrooy - Chatventure wrote:

> Hi,
> 
> I just got my data indexed and I'm able to add some facets to it. Right now I want to filter the selected values of the facets. I took a look at the filtered query, however, only one filter can be added.  
> What's the best way of doing that? The query I used right now looks like this:
> 
> {  
> "query":{  
> "filtered":{  
> "query":{  
> "match\_all":{
> 
> }  
> },  
> "filter":{  
> "terms":{  
> "shop.id":[  
> 192,  
> 182  
> ]  
> }  
> }  
> }  
> },  
> "size":25,  
> "highlight":{  
> "tags\_schema":"styled",  
> "fields":{  
> "\_all":[
> 
> ],  
> "name":[
> 
> ],  
> "description":{  
> "fragment\_size":50  
> }  
> }  
> },  
> "sort":{  
> "price":"desc"  
> },  
> "facets":{  
> "facet\_brand":{  
> "terms":{  
> "field":"brand",  
> "size":10,  
> "order":"count",  
> "exclude":[  
> ""  
> ]  
> }  
> },  
> "facet\_price":{  
> "range":{  
> "field":"price",  
> "ranges":[  
> {  
> "from":null,  
> "to":20  
> },  
> {  
> "from":20,  
> "to":100  
> },  
> {  
> "from":100,  
> "to":500  
> },  
> {  
> "from":500,  
> "to":null  
> }  
> ]  
> }  
> }  
> }  
> }
> 
> Thanks!
> 
> Jasper

---

<div class="post-metadata">

**Author:** ![Jasper\_van\_Wanrooy\_C](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasper_van_wanrooy_c/32/2494_2.png) [@Jasper\_van\_Wanrooy\_C](https://discuss.elastic.co/u/Jasper_van_Wanrooy_C)\
**Post date:** [April 26, 2011, 10:22pm UTC](https://discuss.elastic.co/t/multiple-filters-for-facets/4290/3 "2011-04-26T22:22:03Z")

</div>

Thanks Shay! Now it's totally clear. First facets are created!

On 26 apr 2011, at 19:48, Shay Banon wrote:

> Even if "one" filter can be placed where a filter can be placed, there are and, or, not filters which allow to build more compound filters.
> 
> Check the filter element in search API, it is aimed specifically for facet navigation (and can work better than filtered query feature wise for this scenario): [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/filter.html).
> 
> Also, each facet can have an associated filter using the facet\_filter element: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/) (check Filter at the end).
> 
> -shay.banon  
> On Tuesday, April 26, 2011 at 12:54 AM, Jasper van Wanrooy - Chatventure wrote:
> 
> > Hi,
> > 
> > I just got my data indexed and I'm able to add some facets to it. Right now I want to filter the selected values of the facets. I took a look at the filtered query, however, only one filter can be added.  
> > What's the best way of doing that? The query I used right now looks like this:
> > 
> > {  
> > "query":{  
> > "filtered":{  
> > "query":{  
> > "match\_all":{
> > 
> > }  
> > },  
> > "filter":{  
> > "terms":{  
> > "shop.id":[  
> > 192,  
> > 182  
> > ]]  
> > }  
> > }  
> > }  
> > },  
> > "size":25,  
> > "highlight":{  
> > "tags\_schema":"styled",  
> > "fields":{  
> > "\_all":[
> > 
> > ],  
> > "name":[
> > 
> > ],  
> > ""description":{  
> > "fragment\_size":50  
> > }}  
> > }  
> > },  
> > "sort":{  
> > "price":"desc"  
> > },  
> > "facets":{  
> > "facet\_brand":{  
> > "terms":{  
> > "field":"brand",  
> > ""size":10,  
> > "order":"count",  
> > ""exclude":[  
> > ""  
> > ]  
> > }  
> > },  
> > "facet\_price":{  
> > "range":{  
> > "field":"price",  
> > "ranges":[  
> > {  
> > "from":null,  
> > "to":20  
> > },  
> > {  
> > "from":20,  
> > "to":100  
> > },  
> > {  
> > "from":100,  
> > "to":500  
> > },  
> > {{  
> > "from":500,  
> > ""to":null  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }
> > 
> > Thanks!
> > 
> > Jasper

---

<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 6, 2017, 4:07am UTC](https://discuss.elastic.co/t/multiple-filters-for-facets/4290/4 "2017-07-06T04:07:35Z")

</div>


