# How to get facets without facet filter aplied

**URL:** <https://discuss.elastic.co/t/how-to-get-facets-without-facet-filter-aplied/6115>\
**Category:** Elasticsearch\
**Created:** [December 10, 2011, 5:16am UTC](https://discuss.elastic.co/t/how-to-get-facets-without-facet-filter-aplied/6115 "2011-12-10T05:16:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrik\_Votocek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrik_votocek/32/2027_2.png) [@Patrik\_Votocek](https://discuss.elastic.co/u/Patrik_Votocek)\
**Post date:** [December 10, 2011, 5:16am UTC](https://discuss.elastic.co/t/how-to-get-facets-without-facet-filter-aplied/6115/1 "2011-12-10T05:16:15Z")

</div>

Hi,

how do I select facets without aplied selected "facet filter"?  
Original query [https://gist.github.com/9bd1e1bc4bf289a576cc](https://gist.github.com/9bd1e1bc4bf289a576cc) query with  
aplied "facet filter" [https://gist.github.com/a1eeda6e47f8e972e5df](https://gist.github.com/a1eeda6e47f8e972e5df).

Diff with this two queries is add must term for user (from facets).  
Hits is OK but I need same data in facets as first query. How to do it?

---

<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:** [December 10, 2011, 7:42am UTC](https://discuss.elastic.co/t/how-to-get-facets-without-facet-filter-aplied/6115/2 "2011-12-10T07:42:30Z")

</div>

I think that you have to send two different request to ES.

HTH  
David 😉  
@dadoonet

Le 10 déc. 2011 à 06:16, Patrik Votoček [patrik@votocek.cz](mailto:patrik@votocek.cz) a écrit :

> Hi,
> 
> how do I select facets without aplied selected "facet filter"?  
> Original query [https://gist.github.com/9bd1e1bc4bf289a576cc](https://gist.github.com/9bd1e1bc4bf289a576cc) query with  
> aplied "facet filter" [https://gist.github.com/a1eeda6e47f8e972e5df](https://gist.github.com/a1eeda6e47f8e972e5df).
> 
> Diff with this two queries is add must term for user (from facets).  
> Hits is OK but I need same data in facets as first query. How to do it?

---

<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 10, 2011, 5:59pm UTC](https://discuss.elastic.co/t/how-to-get-facets-without-facet-filter-aplied/6115/3 "2011-12-10T17:59:47Z")

</div>

> I think that you have to send two different request to ES.

No, I think its possible to avoid binding the facet to the query. You  
can change the scope of the facet via

"global" : true

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

Also this search only filter could be of some use:

> <https://github.com/elastic/elasticsearch/issues/650>
>
> When doing things like facet navigation, sometimes only the hits are needed to b…e filtered by the chosen facet, and all the facets should continue to be calculated based on the original query. The new \`filter\` element within the search request can be used to accomplish it.
> 
> For example, lets create two tweets, with two different tags:
> 
> \`\`\`
> curl -XPUT 'localhost:9200/twitter/tweet/1' -d '
> {
> "message" : "something blue",
> "tag" : "blue"
> }
> '
> 
> curl -XPUT 'localhost:9200/twitter/tweet/2' -d '
> {
> "message" : "something green",
> "tag" : "green"
> }
> '
> 
> curl -XPOST 'localhost:9200/\_refresh'
> \`\`\`
> 
> We can now search for \`something\`, and have a \`terms\` facet. 
> 
> \`\`\`
> curl -XPOST 'localhost:9200/twitter/\_search?pretty=true' -d '
> {
> "query" : {
> "term" : { "message" : "something" }
> },
> "facets" : {
> "tag" : {
> "terms" : { "field" : "tag" }
> }
> }
> }
> '
> \`\`\`
> 
> We get two hits, and the relevant facets with a count of \`1\` for both \`green\` and \`blue\`. Now, lets say the \`green\` facet is chosen, we can simply add a filter for it:
> 
> \`\`\`
> curl -XPOST 'localhost:9200/twitter/\_search?pretty=true' -d '
> {
> "query" : {
> "term" : { "message" : "something" }
> },
> "filter" : {
> "term" : { "tag" : "green" }
> },
> "facets" : {
> "tag" : {
> "terms" : { "field" : "tag" }
> }
> }
> }
> '
> \`\`\`
> 
> And now, we get only 1 hit back, but the facets remain the same.
> 
> Note, if additional filters is required on specific facets, they can be added as a \`facet\_filter\` to the relevant facets.

Peter.

On 10 Dez., 08:42, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> I think that you have to send two different request to ES.
> 
> HTH  
> David 😉  
> @dadoonet
> 
> Le 10 déc. 2011 à 06:16, Patrik Votoček [pat...@votocek.cz](mailto:pat...@votocek.cz) a écrit :
> 
> > Hi,
> 
> > how do I select facets without aplied selected "facet filter"?  
> > Original queryhttps://gist.github.com/9bd1e1bc4bf289a576ccquery with  
> > aplied "facet filter"[https://gist.github.com/a1eeda6e47f8e972e5df](https://gist.github.com/a1eeda6e47f8e972e5df).
> 
> > Diff with this two queries is add must term for user (from facets).  
> > Hits is OK but I need same data in facets as first query. How to do it?

---

<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:** [December 10, 2011, 6:11pm UTC](https://discuss.elastic.co/t/how-to-get-facets-without-facet-filter-aplied/6115/4 "2011-12-10T18:11:46Z")

</div>

That means that I have to learn more and more about ES !

David 😉  
@dadoonet

Le 10 déc. 2011 à 18:59, Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com) a écrit :

> > I think that you have to send two different request to ES.
> 
> No, I think its possible to avoid binding the facet to the query. You  
> can change the scope of the facet via
> 
> "global" : true
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html)
> 
> Also this search only filter could be of some use:
> 
> [Search: Allow to pass a search filter, applying only on the query (and not on facets for example) · Issue #650 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/650)
> 
> Peter.
> 
> On 10 Dez., 08:42, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > I think that you have to send two different request to ES.
> > 
> > HTH  
> > David 😉  
> > @dadoonet
> > 
> > Le 10 déc. 2011 à 06:16, Patrik Votoček [pat...@votocek.cz](mailto:pat...@votocek.cz) a écrit :
> > 
> > > Hi,
> > 
> > > how do I select facets without aplied selected "facet filter"?  
> > > Original queryhttps://gist.github.com/9bd1e1bc4bf289a576ccquery with  
> > > aplied "facet filter"[https://gist.github.com/a1eeda6e47f8e972e5df](https://gist.github.com/a1eeda6e47f8e972e5df).
> > 
> > > Diff with this two queries is add must term for user (from facets).  
> > > Hits is OK but I need same data in facets as first query. How to do it?

---

<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:45am UTC](https://discuss.elastic.co/t/how-to-get-facets-without-facet-filter-aplied/6115/5 "2017-07-06T03:45:47Z")

</div>


