# Multi Filitered Facet Queries

**URL:** <https://discuss.elastic.co/t/multi-filitered-facet-queries/4679>\
**Category:** Elasticsearch\
**Created:** [June 21, 2011, 10:06pm UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679 "2011-06-21T22:06:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Owen\_Coutts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/owen_coutts/32/3179_2.png) [@Owen\_Coutts](https://discuss.elastic.co/u/Owen_Coutts)\
**Post date:** [June 21, 2011, 10:06pm UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/1 "2011-06-21T22:06:55Z")

</div>

Hello,

I'm having trouble getting the following query to return any facet results:  
{  
"query" : {  
"term":{  
"tests\_passed":"4",  
"tests\_failed":"1"  
}  
},  
"facets" : {  
"tag" : {  
"terms" : {  
"field" : "system",  
"size" : 10  
}  
}  
}  
}

The following query returns the expected results:  
{  
"query" : {  
"term":{  
"tests\_passed":"1"  
}  
},  
"facets" : {  
"foo" : {  
"terms" : {  
"field" : "system",  
"size" : 10  
}  
}  
}  
}

As does this one:  
{  
"query" : {  
"term":{  
"tests\_passed":"4",  
"tests\_failed":"1"  
}  
}  
}

Am I combigning them improperly? It seems that query is limited to only one  
term filter otherwise the filter disapears. Anyone have any advice?

Thanks,  
Owen

--  
Owen Coutts  
University of Waterloo  
Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 21, 2011, 10:43pm UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/2 "2011-06-21T22:43:06Z")

</div>

Perhaps a boolean query with two terms query could help ?

Something like :

{

```
"bool" : {

    "must" : {

        "term" : { " tests_passed " : "4" }

    },

    "must" : {

        "term" : { " tests_failed " : "1" }

    }

}

```

}

Or

{

```
"bool" : {

    "must" : {

        "term" : { " tests_passed " : "4" },

        "term" : { " tests_failed " : "1" }

    }

}

```

}

BTW, why dont you map tests\_xxx fields to number type ? It could be useful  
to make range facets (if needed)

Hope this helps

David.

De : [owen.coutts@gmail.com](mailto:owen.coutts@gmail.com) [[mailto:owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)] De la part de Owen  
Coutts  
Envoyé : mercredi 22 juin 2011 00:07  
À : [users@elasticsearch.com](mailto:users@elasticsearch.com)  
Objet : Multi Filitered Facet Queries

Hello,

I'm having trouble getting the following query to return any facet results:  
{  
"query" : {  
"term":{  
"tests\_passed":"4",  
"tests\_failed":"1"  
}  
},  
"facets" : {  
"tag" : {  
"terms" : {  
"field" : "system",  
"size" : 10  
}  
}  
}  
}

The following query returns the expected results:  
{  
"query" : {  
"term":{  
"tests\_passed":"1"  
}  
},  
"facets" : {  
"foo" : {  
"terms" : {  
"field" : "system",  
"size" : 10  
}  
}  
}  
}

As does this one:  
{  
"query" : {  
"term":{  
"tests\_passed":"4",  
"tests\_failed":"1"  
}  
}  
}

Am I combigning them improperly? It seems that query is limited to only one  
term filter otherwise the filter disapears. Anyone have any advice?

Thanks,  
Owen

--  
Owen Coutts  
University of Waterloo

Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)

---

<div class="post-metadata">

**Author:** ![Owen\_Coutts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/owen_coutts/32/3179_2.png) [@Owen\_Coutts](https://discuss.elastic.co/u/Owen_Coutts)\
**Post date:** [June 23, 2011, 10:10pm UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/3 "2011-06-23T22:10:08Z")

</div>

Hello,

I tried the suggestion to use bool filters:

{  
"query" : {  
"match\_all" : { }  
},  
"facets" : {  
"tag" : {  
"terms" : {  
"field" : "system",  
"size" : 10  
},  
"filter" : {  
"bool" : {  
"must" : [  
{  
"term" : { "tests\_passed" : "4" }  
},  
{  
"term" : { "tests\_failed" : "1" }  
}  
]  
}  
}  
}  
}  
}

But this didn't return facets by the field "system" (It uses slightly  
different syntax but I think this is what was meant). Am I going about this  
the wrong way?

Thanks,  
Owen Coutts

On Tue, Jun 21, 2011 at 3:43 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Perhaps a boolean query with two terms query could help ?\*\*\*\*
> 
> * * *
> 
> Something like :\*\*\*\*
> 
> {\*\*\*\*
> 
> ```
> "bool" : { ****
> 
> "must" : { ****
> 
> "term" : { " tests_passed " : "4" } ****
> 
> }, ****
> 
> "must" : { ****
> 
> "term" : { " tests_failed " : "1" } ****
> 
> } ****
> 
> } ****
> 
> ```
> 
> }\*\*\*\*
> 
> * * *
> 
> Or\*\*\*\*
> 
> {\*\*\*\*
> 
> ```
> "bool" : { ****
> 
> "must" : { ****
> 
> "term" : { " tests_passed " : "4" }, ****
> 
> "term" : { " tests_failed " : "1" } ****
> 
> } ****
> 
> } ****
> 
> ```
> 
> }\*\*\*\*
> 
> * * *
> 
> BTW, why don’t you map tests\_xxx fields to number type ? It could be useful  
> to make range facets (if needed)…\*\*\*\*
> 
> * * *
> 
> Hope this helps\*\*\*\*
> 
> David.\*\*\*\*
> 
> * * *
> 
> _De :_ [owen.coutts@gmail.com](mailto:owen.coutts@gmail.com) [[mailto:owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)] \*De la part de
> 
> - Owen Coutts  
> _Envoyé :_ mercredi 22 juin 2011 00:07  
> _À :_ [users@elasticsearch.com](mailto:users@elasticsearch.com)  
> _Objet :_ Multi Filitered Facet Queries\*\*\*\*
> 
> * * *
> 
> Hello,
> 
> I'm having trouble getting the following query to return any facet results:  
> {  
> "query" : {  
> "term":{  
> "tests\_passed":"4",  
> "tests\_failed":"1"  
> }  
> },  
> "facets" : {  
> "tag" : {  
> "terms" : {  
> "field" : "system",  
> "size" : 10  
> }  
> }  
> }  
> }
> 
> The following query returns the expected results:  
> {  
> "query" : {  
> "term":{  
> "tests\_passed":"1"  
> }  
> },  
> "facets" : {  
> "foo" : {  
> "terms" : {  
> "field" : "system",  
> "size" : 10  
> }  
> }  
> }  
> }
> 
> As does this one:  
> {  
> "query" : {  
> "term":{  
> "tests\_passed":"4",  
> "tests\_failed":"1"  
> }  
> }  
> }
> 
> Am I combigning them improperly? It seems that query is limited to only one  
> term filter otherwise the filter disapears. Anyone have any advice?
> 
> Thanks,  
> Owen
> 
> --  
> Owen Coutts  
> University of Waterloo\*\*\*\*
> 
> Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)\*\*\*\*
> 
> * * *

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 23, 2011, 10:16pm UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/4 "2011-06-23T22:16:48Z")

</div>

Not sure but I think that you have to filter at the same level as query.  
Something like :

> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "filter" : { ... },  
> "facets" : { ... } }

as you want to filter the match\_all query...

David 😉

Le 24 juin 2011 à 00:10, Owen Coutts [owen@owencoutts.com](mailto:owen@owencoutts.com) a écrit :

> Hello,
> 
> I tried the suggestion to use bool filters:
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "facets" : {  
> "tag" : {  
> "terms" : {  
> "field" : "system",  
> "size" : 10  
> },  
> "filter" : {  
> "bool" : {  
> "must" : [  
> {  
> "term" : { "tests\_passed" : "4" }  
> },  
> {  
> "term" : { "tests\_failed" : "1" }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> But this didn't return facets by the field "system" (It uses slightly different syntax but I think this is what was meant). Am I going about this the wrong way?
> 
> Thanks,  
> Owen Coutts
> 
> On Tue, Jun 21, 2011 at 3:43 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> Perhaps a boolean query with two terms query could help ?
> 
> Something like :
> 
> {
> 
> ```
> "bool" : {
> 
> "must" : {
> 
> "term" : { " tests_passed " : "4" }
> 
> },
> 
> "must" : {
> 
> "term" : { " tests_failed " : "1" }
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> Or
> 
> {
> 
> ```
> "bool" : {
> 
> "must" : {
> 
> "term" : { " tests_passed " : "4" },
> 
> "term" : { " tests_failed " : "1" }
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> BTW, why don’t you map tests\_xxx fields to number type ? It could be useful to make range facets (if needed)…
> 
> Hope this helps
> 
> David.
> 
> De : [owen.coutts@gmail.com](mailto:owen.coutts@gmail.com) [[mailto:owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)] De la part de Owen Coutts  
> Envoyé : mercredi 22 juin 2011 00:07  
> À : [users@elasticsearch.com](mailto:users@elasticsearch.com)  
> Objet : Multi Filitered Facet Queries
> 
> Hello,
> 
> I'm having trouble getting the following query to return any facet results:  
> {  
> "query" : {  
> "term":{  
> "tests\_passed":"4",  
> "tests\_failed":"1"  
> }  
> },  
> "facets" : {  
> "tag" : {  
> "terms" : {  
> "field" : "system",  
> "size" : 10  
> }  
> }  
> }  
> }
> 
> The following query returns the expected results:  
> {  
> "query" : {  
> "term":{  
> "tests\_passed":"1"  
> }  
> },  
> "facets" : {  
> "foo" : {  
> "terms" : {  
> "field" : "system",  
> "size" : 10  
> }  
> }  
> }  
> }
> 
> As does this one:  
> {  
> "query" : {  
> "term":{  
> "tests\_passed":"4",  
> "tests\_failed":"1"  
> }  
> }  
> }
> 
> Am I combigning them improperly? It seems that query is limited to only one term filter otherwise the filter disapears. Anyone have any advice?
> 
> Thanks,  
> Owen
> 
> --  
> Owen Coutts  
> University of Waterloo
> 
> Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)

---

<div class="post-metadata">

**Author:** ![Owen\_Coutts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/owen_coutts/32/3179_2.png) [@Owen\_Coutts](https://discuss.elastic.co/u/Owen_Coutts)\
**Post date:** [June 24, 2011, 11:02pm UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/5 "2011-06-24T23:02:26Z")

</div>

It seems like it doesn't actually filter the facets if you do that.

On Thu, Jun 23, 2011 at 3:16 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Not sure but I think that you have to filter at the same level as query.  
> Something like :
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },
> 
> ```
> "filter" : { ... },
> 
> "facets" : { ... } }
> 
> ```
> 
> as you want to filter the match\_all query...
> 
> David 😉
> 
> Le 24 juin 2011 à 00:10, Owen Coutts [owen@owencoutts.com](mailto:owen@owencoutts.com) a écrit :
> 
> Hello,
> 
> I tried the suggestion to use bool filters:
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "facets" : {  
> "tag" : {  
> "terms" : {  
> "field" : "system",  
> "size" : 10  
> },  
> "filter" : {  
> "bool" : {  
> "must" : [  
> {  
> "term" : { "tests\_passed" : "4" }  
> },  
> {  
> "term" : { "tests\_failed" : "1" }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> But this didn't return facets by the field "system" (It uses slightly  
> different syntax but I think this is what was meant). Am I going about this  
> the wrong way?
> 
> Thanks,  
> Owen Coutts
> 
> On Tue, Jun 21, 2011 at 3:43 PM, David Pilato \< [david@pilato.fr](mailto:david@pilato.fr)  
> [david@pilato.fr](mailto:david@pilato.fr)\> wrote:
> 
> > Perhaps a boolean query with two terms query could help ?\*\*\*\*
> > 
> > * * *
> > 
> > Something like :\*\*\*\*
> > 
> > {\*\*\*\*
> > 
> > ```
> > "bool" : { ****
> > 
> > "must" : { ****
> > 
> > "term" : { " tests_passed " : "4" } ****
> > 
> > }, ****
> > 
> > "must" : { ****
> > 
> > "term" : { " tests_failed " : "1" } ****
> > 
> > } ****
> > 
> > } ****
> > 
> > ```
> > 
> > }\*\*\*\*
> > 
> > * * *
> > 
> > Or\*\*\*\*
> > 
> > {\*\*\*\*
> > 
> > ```
> > "bool" : { ****
> > 
> > "must" : { ****
> > 
> > "term" : { " tests_passed " : "4" }, ****
> > 
> > "term" : { " tests_failed " : "1" } ****
> > 
> > } ****
> > 
> > } ****
> > 
> > ```
> > 
> > }\*\*\*\*
> > 
> > * * *
> > 
> > BTW, why don’t you map tests\_xxx fields to number type ? It could be  
> > useful to make range facets (if needed)…\*\*\*\*
> > 
> > * * *
> > 
> > Hope this helps\*\*\*\*
> > 
> > David.\*\*\*\*
> > 
> > * * *
> > 
> > _De :_ [owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)[owen.coutts@gmail.com](mailto:owen.coutts@gmail.com) [mailto:[owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)  
> > [owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)] _De la part de_ Owen Coutts  
> > _Envoyé :_ mercredi 22 juin 2011 00:07  
> > _À :_ [users@elasticsearch.com](mailto:users@elasticsearch.com)[users@elasticsearch.com](mailto:users@elasticsearch.com)  
> > _Objet :_ Multi Filitered Facet Queries\*\*\*\*
> > 
> > * * *
> > 
> > Hello,
> > 
> > I'm having trouble getting the following query to return any facet  
> > results:  
> > {  
> > "query" : {  
> > "term":{  
> > "tests\_passed":"4",  
> > "tests\_failed":"1"  
> > }  
> > },  
> > "facets" : {  
> > "tag" : {  
> > "terms" : {  
> > "field" : "system",  
> > "size" : 10  
> > }  
> > }  
> > }  
> > }
> > 
> > The following query returns the expected results:  
> > {  
> > "query" : {  
> > "term":{  
> > "tests\_passed":"1"  
> > }  
> > },  
> > "facets" : {  
> > "foo" : {  
> > "terms" : {  
> > "field" : "system",  
> > "size" : 10  
> > }  
> > }  
> > }  
> > }
> > 
> > As does this one:  
> > {  
> > "query" : {  
> > "term":{  
> > "tests\_passed":"4",  
> > "tests\_failed":"1"  
> > }  
> > }  
> > }
> > 
> > Am I combigning them improperly? It seems that query is limited to only  
> > one term filter otherwise the filter disapears. Anyone have any advice?
> > 
> > Thanks,  
> > Owen
> > 
> > --  
> > Owen Coutts  
> > University of Waterloo\*\*\*\*
> > 
> > Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)[owen@owencoutts.com](mailto:owen@owencoutts.com)\*\*\*\*
> > 
> > * * *

--  
Owen Coutts  
University of Waterloo

--  
Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)  
Phone: 519.729.3859  
Book a Meeting With Me: [tungle.me/ocoutts](http://tungle.me/ocoutts)

---

<div class="post-metadata">

**Author:** ![IvanBrusic](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@IvanBrusic](https://discuss.elastic.co/u/IvanBrusic)\
**Post date:** [June 25, 2011, 4:00am UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/6 "2011-06-25T04:00:41Z")

</div>

What you want for facet filters, not "normal" filters.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Whenever you execute a query, you can return results AND a set of  
facets unless you select a size of zero. The filters work on the  
query and have no affect on the facets.

--  
Ivan

On Jun 24, 7:02 pm, Owen Coutts [o...@owencoutts.com](mailto:o...@owencoutts.com) wrote:

> It seems like it doesn't actually filter the facets if you do that.
> 
> On Thu, Jun 23, 2011 at 3:16 PM, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > Not sure but I think that you have to filter at the same level as query.  
> > Something like :
> 
> > {  
> > "query" : {  
> > "match\_all" : { }  
> > },
> 
> > ```
> > "filter" : { ... },
> > 
> > ```
> 
> > ```
> > "facets" : { ... } }
> > 
> > ```
> 
> > as you want to filter the match\_all query...
> 
> > David 😉
> 
> > Le 24 juin 2011 à 00:10, Owen Coutts [o...@owencoutts.com](mailto:o...@owencoutts.com) a écrit :
> 
> > Hello,
> 
> > I tried the suggestion to use bool filters:
> 
> > {  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "facets" : {  
> > "tag" : {  
> > "terms" : {  
> > "field" : "system",  
> > "size" : 10  
> > },  
> > "filter" : {  
> > "bool" : {  
> > "must" : [  
> > {  
> > "term" : { "tests\_passed" : "4" }  
> > },  
> > {  
> > "term" : { "tests\_failed" : "1" }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }
> 
> > But this didn't return facets by the field "system" (It uses slightly  
> > different syntax but I think this is what was meant). Am I going about this  
> > the wrong way?
> 
> > Thanks,  
> > Owen Coutts
> 
> > On Tue, Jun 21, 2011 at 3:43 PM, David Pilato \< [da...@pilato.fr](mailto:da...@pilato.fr)  
> > [da...@pilato.fr](mailto:da...@pilato.fr)\> wrote:
> 
> > > Perhaps a boolean query with two terms query could help ?\*\*\*\*
> 
> > > * * *
> 
> > > Something like :\*\*\*\*
> 
> > > {\*\*\*\*
> 
> > > ```
> > > "bool" : { ****
> > > 
> > > ```
> 
> > > ```
> > > "must" : { ****
> > > 
> > > ```
> 
> > > ```
> > > "term" : { " tests_passed " : "4" } ****
> > > 
> > > ```
> 
> > > ```
> > > }, ****
> > > 
> > > ```
> 
> > > ```
> > > "must" : { ****
> > > 
> > > ```
> 
> > > ```
> > > "term" : { " tests_failed " : "1" } ****
> > > 
> > > ```
> 
> > > ```
> > > } ****
> > > 
> > > ```
> 
> > > ```
> > > } ****
> > > 
> > > ```
> 
> > > }\*\*\*\*
> 
> > > * * *
> 
> > > Or\*\*\*\*
> 
> > > {\*\*\*\*
> 
> > > ```
> > > "bool" : { ****
> > > 
> > > ```
> 
> > > ```
> > > "must" : { ****
> > > 
> > > ```
> 
> > > ```
> > > "term" : { " tests_passed " : "4" }, ****
> > > 
> > > ```
> 
> > > ```
> > > "term" : { " tests_failed " : "1" } ****
> > > 
> > > ```
> 
> > > ```
> > > } ****
> > > 
> > > ```
> 
> > > ```
> > > } ****
> > > 
> > > ```
> 
> > > }\*\*\*\*
> 
> > > * * *
> 
> > > BTW, why don’t you map tests\_xxx fields to number type ? It could be  
> > > useful to make range facets (if needed)…\*\*\*\*
> 
> > > * * *
> 
> > > Hope this helps\*\*\*\*
> 
> > > David.\*\*\*\*
> 
> > > * * *
> 
> > > _De :_ [owen.cou...@gmail.com](mailto:owen.cou...@gmail.com)[owen.cou...@gmail.com](mailto:owen.cou...@gmail.com) [mailto:[owen.cou...@gmail.com](mailto:owen.cou...@gmail.com)  
> > > [owen.cou...@gmail.com](mailto:owen.cou...@gmail.com)] _De la part de_ Owen Coutts  
> > > _Envoyé :_ mercredi 22 juin 2011 00:07  
> > > _À :_ [us...@elasticsearch.com](mailto:us...@elasticsearch.com)[us...@elasticsearch.com](mailto:us...@elasticsearch.com)  
> > > _Objet :_ Multi Filitered Facet Queries\*\*\*\*
> 
> > > * * *
> 
> > > Hello,
> 
> > > I'm having trouble getting the following query to return any facet  
> > > results:  
> > > {  
> > > "query" : {  
> > > "term":{  
> > > "tests\_passed":"4",  
> > > "tests\_failed":"1"  
> > > }  
> > > },  
> > > "facets" : {  
> > > "tag" : {  
> > > "terms" : {  
> > > "field" : "system",  
> > > "size" : 10  
> > > }  
> > > }  
> > > }  
> > > }
> 
> > > The following query returns the expected results:  
> > > {  
> > > "query" : {  
> > > "term":{  
> > > "tests\_passed":"1"  
> > > }  
> > > },  
> > > "facets" : {  
> > > "foo" : {  
> > > "terms" : {  
> > > "field" : "system",  
> > > "size" : 10  
> > > }  
> > > }  
> > > }  
> > > }
> 
> > > As does this one:  
> > > {  
> > > "query" : {  
> > > "term":{  
> > > "tests\_passed":"4",  
> > > "tests\_failed":"1"  
> > > }  
> > > }  
> > > }
> 
> > > Am I combigning them improperly? It seems that query is limited to only  
> > > one term filter otherwise the filter disapears. Anyone have any advice?
> 
> > > Thanks,  
> > > Owen
> 
> > > --  
> > > Owen Coutts  
> > > University of Waterloo\*\*\*\*
> 
> > > Email: [o...@owencoutts.com](mailto:o...@owencoutts.com)[o...@owencoutts.com](mailto:o...@owencoutts.com)\*\*\*\*
> 
> > > * * *
> 
> --  
> Owen Coutts  
> University of Waterloo
> 
> --  
> Email: [o...@owencoutts.com](mailto:o...@owencoutts.com)  
> Phone: 519.729.3859  
> Book a Meeting With Me: [tungle.me/ocoutts](http://tungle.me/ocoutts)

---

<div class="post-metadata">

**Author:** ![Adrian\_Gaudebert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrian_gaudebert/32/3161_2.png) [@Adrian\_Gaudebert](https://discuss.elastic.co/u/Adrian_Gaudebert)\
**Post date:** [June 25, 2011, 5:06am UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/7 "2011-06-25T05:06:52Z")

</div>

The last dude may be right: in a facet, you have to use "facet\_filter"  
instead of "filter".

On Fri, Jun 24, 2011 at 4:02 PM, Owen Coutts [owen@owencoutts.com](mailto:owen@owencoutts.com) wrote:

> It seems like it doesn't actually filter the facets if you do that.
> 
> On Thu, Jun 23, 2011 at 3:16 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Not sure but I think that you have to filter at the same level as query.  
> > Something like :
> > 
> > {  
> > "query" : {  
> > "match\_all" : { }  
> > },
> > 
> > ```
> > "filter" : { ... },
> > 
> > "facets" : { ... } }
> > 
> > ```
> > 
> > as you want to filter the match\_all query...
> > 
> > David 😉
> > 
> > Le 24 juin 2011 à 00:10, Owen Coutts [owen@owencoutts.com](mailto:owen@owencoutts.com) a écrit :
> > 
> > Hello,
> > 
> > I tried the suggestion to use bool filters:
> > 
> > {  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "facets" : {  
> > "tag" : {  
> > "terms" : {  
> > "field" : "system",  
> > "size" : 10  
> > },  
> > "filter" : {  
> > "bool" : {  
> > "must" : [  
> > {  
> > "term" : { "tests\_passed" : "4" }  
> > },  
> > {  
> > "term" : { "tests\_failed" : "1" }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > But this didn't return facets by the field "system" (It uses slightly  
> > different syntax but I think this is what was meant). Am I going about this  
> > the wrong way?
> > 
> > Thanks,  
> > Owen Coutts
> > 
> > On Tue, Jun 21, 2011 at 3:43 PM, David Pilato \< [david@pilato.fr](mailto:david@pilato.fr)  
> > [david@pilato.fr](mailto:david@pilato.fr)\> wrote:
> > 
> > > Perhaps a boolean query with two terms query could help ?\*\*\*\*
> > > 
> > > * * *
> > > 
> > > Something like :\*\*\*\*
> > > 
> > > {\*\*\*\*
> > > 
> > > ```
> > > "bool" : { ****
> > > 
> > > "must" : { ****
> > > 
> > > "term" : { " tests_passed " : "4" } ****
> > > 
> > > }, ****
> > > 
> > > "must" : { ****
> > > 
> > > "term" : { " tests_failed " : "1" } ****
> > > 
> > > } ****
> > > 
> > > } ****
> > > 
> > > ```
> > > 
> > > }\*\*\*\*
> > > 
> > > * * *
> > > 
> > > Or\*\*\*\*
> > > 
> > > {\*\*\*\*
> > > 
> > > ```
> > > "bool" : { ****
> > > 
> > > "must" : { ****
> > > 
> > > "term" : { " tests_passed " : "4" }, ****
> > > 
> > > "term" : { " tests_failed " : "1" } ****
> > > 
> > > } ****
> > > 
> > > } ****
> > > 
> > > ```
> > > 
> > > }\*\*\*\*
> > > 
> > > * * *
> > > 
> > > BTW, why don’t you map tests\_xxx fields to number type ? It could be  
> > > useful to make range facets (if needed)…\*\*\*\*
> > > 
> > > * * *
> > > 
> > > Hope this helps\*\*\*\*
> > > 
> > > David.\*\*\*\*
> > > 
> > > * * *
> > > 
> > > _De :_ [owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)[owen.coutts@gmail.com](mailto:owen.coutts@gmail.com) [mailto:[owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)  
> > > [owen.coutts@gmail.com](mailto:owen.coutts@gmail.com)] _De la part de_ Owen Coutts  
> > > _Envoyé :_ mercredi 22 juin 2011 00:07  
> > > _À :_ [users@elasticsearch.com](mailto:users@elasticsearch.com)[users@elasticsearch.com](mailto:users@elasticsearch.com)  
> > > _Objet :_ Multi Filitered Facet Queries\*\*\*\*
> > > 
> > > * * *
> > > 
> > > Hello,
> > > 
> > > I'm having trouble getting the following query to return any facet  
> > > results:  
> > > {  
> > > "query" : {  
> > > "term":{  
> > > "tests\_passed":"4",  
> > > "tests\_failed":"1"  
> > > }  
> > > },  
> > > "facets" : {  
> > > "tag" : {  
> > > "terms" : {  
> > > "field" : "system",  
> > > "size" : 10  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > The following query returns the expected results:  
> > > {  
> > > "query" : {  
> > > "term":{  
> > > "tests\_passed":"1"  
> > > }  
> > > },  
> > > "facets" : {  
> > > "foo" : {  
> > > "terms" : {  
> > > "field" : "system",  
> > > "size" : 10  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > As does this one:  
> > > {  
> > > "query" : {  
> > > "term":{  
> > > "tests\_passed":"4",  
> > > "tests\_failed":"1"  
> > > }  
> > > }  
> > > }
> > > 
> > > Am I combigning them improperly? It seems that query is limited to only  
> > > one term filter otherwise the filter disapears. Anyone have any advice?
> > > 
> > > Thanks,  
> > > Owen
> > > 
> > > --  
> > > Owen Coutts  
> > > University of Waterloo\*\*\*\*
> > > 
> > > Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)[owen@owencoutts.com](mailto:owen@owencoutts.com)\*\*\*\*
> > > 
> > > * * *
> 
> --  
> Owen Coutts  
> University of Waterloo
> 
> --  
> Email: [owen@owencoutts.com](mailto:owen@owencoutts.com)  
> Phone: 519.729.3859  
> Book a Meeting With Me: [tungle.me/ocoutts](http://tungle.me/ocoutts)

--  
Adrian Gaudebert  
WebDev Intern @ Mozilla  
[http://adrian.gaudebert.fr](http://adrian.gaudebert.fr)

---

<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:02am UTC](https://discuss.elastic.co/t/multi-filitered-facet-queries/4679/8 "2017-07-06T04:02:36Z")

</div>


