# Shared facet filtration

**URL:** <https://discuss.elastic.co/t/shared-facet-filtration/16862>\
**Category:** Elasticsearch\
**Created:** [April 8, 2014, 1:56am UTC](https://discuss.elastic.co/t/shared-facet-filtration/16862 "2014-04-08T01:56:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_G](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Alex\_G](https://discuss.elastic.co/u/Alex_G)\
**Post date:** [April 8, 2014, 1:56am UTC](https://discuss.elastic.co/t/shared-facet-filtration/16862/1 "2014-04-08T01:56:54Z")

</div>

Hello,

I’m implementing a faceted interface that requires that all the facets be  
filtered by a shared filter - below is roughly how the queries currently  
look, is there a more efficient/performant way to make this kind of query?  
Less fussed about actual query verbosity but if there some way of sharing  
or referencing the repeated facet\_filter other than search templates that’d  
be fantastic.

Thanks,

Alex

{  
"facets": {  
"facetOne": {  
"facet\_filter": {  
"bool": {  
"must": [  
{  
"term": {  
"foo.bar": "test"  
}  
},  
{  
"term": {  
"baz":"test\*"  
}  
}  
]  
}  
},  
"terms": {  
"field": "facetOne.field",  
"order": ["count"],  
"size": 50  
}  
},

```
    "facetTwo": {
        "facet_filter": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "foo.bar": "test"
                        }
                    },
                    {
                        "term": {
                            "baz":"test*"
                        }
                    }
                ]
            }
        },
        "terms": {
            "field": "facetTwo.field",
            "order": ["count"],
            "size": 50
        }
    },

    "facetThree": {
        "facet_filter": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "foo.bar": "test"
                        }
                    },
                    {
                        "term": {
                            "baz":"test*"
                        }
                    }
                ]
            }
        },
        "terms": {
            "field": "facetThree.field",
            "order": ["count"],
            "size": 50
        }
    }
},
"size": 0

```

}

--

* * *

_CONFIDENTIALITY NOTICE:_ The information contained in this message may be privileged and/or confidential. It is the property of CrowdStrike. If you are not the intended recipient, or responsible for delivering this message to the intended recipient, any review, forwarding, dissemination, distribution or copying of this communication or any attachment(s) is strictly prohibited. If you have received this message in error, please notify the sender immediately, and delete it and all attachments from your computer and network.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [April 8, 2014, 5:12pm UTC](https://discuss.elastic.co/t/shared-facet-filtration/16862/2 "2014-04-08T17:12:42Z")

</div>

You should be able to use filtered queries instead, where the filter is  
your facet filter:

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

The filtered query will filter documents before the query. Facets work on  
the documents returned by the query, so if the documents are pre-filtered,  
the facets will not even work on them.

--  
Ivan

On Mon, Apr 7, 2014 at 6:56 PM, Alex G [alex.graul@crowdstrike.com](mailto:alex.graul@crowdstrike.com) wrote:

> Hello,
> 
> I'm implementing a faceted interface that requires that all the facets be  
> filtered by a shared filter - below is roughly how the queries currently  
> look, is there a more efficient/performant way to make this kind of query?  
> Less fussed about actual query verbosity but if there some way of sharing  
> or referencing the repeated facet\_filter other than search templates that'd  
> be fantastic.
> 
> Thanks,
> 
> Alex
> 
> {  
> "facets": {  
> "facetOne": {  
> "facet\_filter": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "foo.bar": "test"  
> }  
> },  
> {  
> "term": {  
> "baz":"test\*"  
> }  
> }  
> ]  
> }  
> },  
> "terms": {  
> "field": "facetOne.field",  
> "order": ["count"],  
> "size": 50  
> }  
> },
> 
> ```
> "facetTwo": {
> "facet_filter": {
> "bool": {
> "must": [
> {
> "term": {
> "foo.bar": "test"
> }
> },
> {
> "term": {
> "baz":"test*"
> }
> }
> ]
> }
> },
> "terms": {
> "field": "facetTwo.field",
> "order": ["count"],
> "size": 50
> }
> },
> 
> "facetThree": {
> "facet_filter": {
> "bool": {
> "must": [
> {
> "term": {
> "foo.bar": "test"
> }
> },
> {
> "term": {
> "baz":"test*"
> }
> }
> ]
> }
> },
> "terms": {
> "field": "facetThree.field",
> "order": ["count"],
> "size": 50
> }
> }
> },
> "size": 0
> 
> ```
> 
> }
> 
> * * *
> 
> _CONFIDENTIALITY NOTICE:_ The information contained in this message may be privileged and/or confidential. It is the property of CrowdStrike. If you are not the intended recipient, or responsible for delivering this message to the intended recipient, any review, forwarding, dissemination, distribution or copying of this communication or any attachment(s) is strictly prohibited. If you have received this message in error, please notify the sender immediately, and delete it and all attachments from your computer and network.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCMqCGyvmv025zuy-GovaKMQkY7GTf5uj63fdJaH8Biaw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCMqCGyvmv025zuy-GovaKMQkY7GTf5uj63fdJaH8Biaw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Alex\_G](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Alex\_G](https://discuss.elastic.co/u/Alex_G)\
**Post date:** [April 10, 2014, 5:35am UTC](https://discuss.elastic.co/t/shared-facet-filtration/16862/3 "2014-04-10T05:35:29Z")

</div>

Fantastic, that's exactly what I was looking for, thankyou!

On Wednesday, April 9, 2014 3:12:42 AM UTC+10, Ivan Brusic wrote:

> You should be able to use filtered queries instead, where the filter is  
> your facet filter:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)
> 
> The filtered query will filter documents before the query. Facets work on  
> the documents returned by the query, so if the documents are pre-filtered,  
> the facets will not even work on them.
> 
> --  
> Ivan
> 
> On Mon, Apr 7, 2014 at 6:56 PM, Alex G \<[alex....@crowdstrike.com](mailto:alex....@crowdstrike.com)\<javascript:\>
> 
> > wrote:
> 
> > Hello,
> > 
> > I’m implementing a faceted interface that requires that all the facets be  
> > filtered by a shared filter - below is roughly how the queries currently  
> > look, is there a more efficient/performant way to make this kind of query?  
> > Less fussed about actual query verbosity but if there some way of sharing  
> > or referencing the repeated facet\_filter other than search templates that’d  
> > be fantastic.
> > 
> > Thanks,
> > 
> > Alex
> > 
> > {  
> > "facets": {  
> > "facetOne": {  
> > "facet\_filter": {  
> > "bool": {  
> > "must": [  
> > {  
> > "term": {  
> > "foo.bar": "test"  
> > }  
> > },  
> > {  
> > "term": {  
> > "baz":"test\*"  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > "terms": {  
> > "field": "facetOne.field",  
> > "order": ["count"],  
> > "size": 50  
> > }  
> > },
> > 
> > ```
> > "facetTwo": {
> > "facet_filter": {
> > "bool": {
> > "must": [
> > {
> > "term": {
> > "foo.bar": "test"
> > }
> > },
> > {
> > "term": {
> > "baz":"test*"
> > }
> > }
> > ]
> > }
> > },
> > "terms": {
> > "field": "facetTwo.field",
> > "order": ["count"],
> > "size": 50
> > }
> > },
> > 
> > "facetThree": {
> > "facet_filter": {
> > "bool": {
> > "must": [
> > {
> > "term": {
> > "foo.bar": "test"
> > }
> > },
> > {
> > "term": {
> > "baz":"test*"
> > }
> > }
> > ]
> > }
> > },
> > "terms": {
> > "field": "facetThree.field",
> > "order": ["count"],
> > "size": 50
> > }
> > }
> > },
> > "size": 0
> > 
> > ```
> > 
> > }
> > 
> > * * *
> > 
> > _CONFIDENTIALITY NOTICE:_ The information contained in this message may be privileged and/or confidential. It is the property of CrowdStrike. If you are not the intended recipient, or responsible for delivering this message to the intended recipient, any review, forwarding, dissemination, distribution or copying of this communication or any attachment(s) is strictly prohibited. If you have received this message in error, please notify the sender immediately, and delete it and all attachments from your computer and network.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0993b970-b60c-4e38-b42c-953394abdac1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--

* * *

_CONFIDENTIALITY NOTICE:_ The information contained in this message may be privileged and/or confidential. It is the property of CrowdStrike. If you are not the intended recipient, or responsible for delivering this message to the intended recipient, any review, forwarding, dissemination, distribution or copying of this communication or any attachment(s) is strictly prohibited. If you have received this message in error, please notify the sender immediately, and delete it and all attachments from your computer and network.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/206d6999-198a-4e01-bdc1-ebadd0a71f0e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/206d6999-198a-4e01-bdc1-ebadd0a71f0e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:36am UTC](https://discuss.elastic.co/t/shared-facet-filtration/16862/4 "2017-07-06T01:36:56Z")

</div>


