# Should the facet\_filter only returns results from that specified facet?

**URL:** <https://discuss.elastic.co/t/should-the-facet-filter-only-returns-results-from-that-specified-facet/6204>\
**Category:** Elasticsearch\
**Created:** [December 21, 2011, 4:13am UTC](https://discuss.elastic.co/t/should-the-facet-filter-only-returns-results-from-that-specified-facet/6204 "2011-12-21T04:13:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrblue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrblue/32/23268_2.png) [@mrblue](https://discuss.elastic.co/u/mrblue)\
**Post date:** [December 21, 2011, 4:13am UTC](https://discuss.elastic.co/t/should-the-facet-filter-only-returns-results-from-that-specified-facet/6204/1 "2011-12-21T04:13:55Z")

</div>

Hi,

i´m not sure if i really understand facet\_filter. I have a query +  
facets + a facet\_filter.

Applying the facet\_filter only the facet specified is returned. OK.  
But i still get all results from the query..

Say facet X is not displayed as it was filtered, i still get results  
only available under facet X. Is this a normal behaviour ?

What does my query / query\_string look like if i want to show all  
tweets by user "john" that contains the string "text" and are tagged  
with the color "blue" ?

thy a lot!

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [December 21, 2011, 7:57am UTC](https://discuss.elastic.co/t/should-the-facet-filter-only-returns-results-from-that-specified-facet/6204/2 "2011-12-21T07:57:31Z")

</div>

This is nicely (IMO :)) explained here:

> **[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.

Peter.

On 21 Dez., 05:13, mrblue [john.agricola...@googlemail.com](mailto:john.agricola...@googlemail.com) wrote:

> Hi,
> 
> i´m not sure if i really understand facet\_filter. I have a query +  
> facets + a facet\_filter.
> 
> Applying the facet\_filter only the facet specified is returned. OK.  
> But i still get all results from the query..
> 
> Say facet X is not displayed as it was filtered, i still get results  
> only available under facet X. Is this a normal behaviour ?
> 
> What does my query / query\_string look like if i want to show all  
> tweets by user "john" that contains the string "text" and are tagged  
> with the color "blue" ?
> 
> thy a lot!

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [December 21, 2011, 9:45am UTC](https://discuss.elastic.co/t/should-the-facet-filter-only-returns-results-from-that-specified-facet/6204/3 "2011-12-21T09:45:47Z")

</div>

Hi John

> iÂ´m not sure if i really understand facet\_filter. I have a query +  
> facets + a facet\_filter.
> 
> Applying the facet\_filter only the facet specified is returned. OK.  
> But i still get all results from the query..

There are numerous places that filters can be applied:

- to a query (affects facets and results)
- to a search (affects results but not facets)
- to a facet (affects facets but not results)

> What does my query / query\_string look like if i want to show all  
> tweets by user "john" that contains the string "text" and are tagged  
> with the color "blue" ?

Your query for the above could look something like this:

curl -XGET '[http://127.0.0.1:9200/\_all/\_search?pretty=1](http://127.0.0.1:9200/_all/_search?pretty=1)' -d '  
{  
"query" : {  
"filtered" : {  
"filter" : {  
"and" : [  
{  
"term" : {  
"tag" : "blue"  
}  
},  
{  
"term" : {  
"user" : "john"  
}  
}  
]  
},  
"query" : {  
"text" : {  
"\_all" : "text"  
}  
}  
}  
}  
}  
'

---

<div class="post-metadata">

**Author:** ![mrblue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrblue/32/23268_2.png) [@mrblue](https://discuss.elastic.co/u/mrblue)\
**Post date:** [December 21, 2011, 1:02pm UTC](https://discuss.elastic.co/t/should-the-facet-filter-only-returns-results-from-that-specified-facet/6204/4 "2011-12-21T13:02:18Z")

</div>

OK, i see.  
My query is:

{  
"query" : { "query\_string" : {"query" : "u\*"} },

```
"facets" : {
  "my-facet-user" : { "terms" : {"field" : "user"
  , "all_terms" : true

  }

```

,  
"facet\_filter" : {  
"term" : { "user" : "john"}  
}

```
  }
}

```

}

But i should filter the query, not the facet 🙂

On Dec 21, 10:45 am, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hi John
> 
> > i´m not sure if i really understand facet\_filter. I have a query +  
> > facets + a facet\_filter.
> 
> > Applying the facet\_filter only the facet specified is returned. OK.  
> > But i still get all results from the query..
> 
> There are numerous places that filters can be applied:
> 
> - to a query (affects facets and results)
> - to a search (affects results but not facets)
> - to a facet (affects facets but not results)
> 
> > What does my query / query\_string look like if i want to show all  
> > tweets by user "john" that contains the string "text" and are tagged  
> > with the color "blue" ?
> 
> Your query for the above could look something like this:
> 
> curl -XGET '[http://127.0.0.1:9200/\_all/\_search?pretty=1](http://127.0.0.1:9200/_all/_search?pretty=1)' -d '  
> {  
> "query" : {  
> "filtered" : {  
> "filter" : {  
> "and" : [  
> {  
> "term" : {  
> "tag" : "blue"  
> }  
> },  
> {  
> "term" : {  
> "user" : "john"  
> }  
> }  
> ]  
> },  
> "query" : {  
> "text" : {  
> "\_all" : "text"  
> }  
> }  
> }  
> }}
> 
> '

---

<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, 3:44am UTC](https://discuss.elastic.co/t/should-the-facet-filter-only-returns-results-from-that-specified-facet/6204/5 "2017-07-06T03:44:43Z")

</div>


