# Named Filters and Faceting

**URL:** <https://discuss.elastic.co/t/named-filters-and-faceting/10220>\
**Category:** Elasticsearch\
**Created:** [January 3, 2013, 6:07pm UTC](https://discuss.elastic.co/t/named-filters-and-faceting/10220 "2013-01-03T18:07:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyeatman74](https://avatars.discourse-cdn.com/v4/letter/k/ebca7d/32.png) [@kyeatman74](https://discuss.elastic.co/u/kyeatman74)\
**Post date:** [January 3, 2013, 6:07pm UTC](https://discuss.elastic.co/t/named-filters-and-faceting/10220/1 "2013-01-03T18:07:57Z")

</div>

I've been working with ElasticSearch for the last 6 months or so and have been very happy with the features and performance. However, I have run into a problem I'm not sure if ES supports.

I have a web application in which users are creating multiple standing queries (sometimes relatively complicated). I've been converting the queries to named filters and running them with the appropriate ANDs and ORs to create the result set. I can tell which result belongs to which query/filter via the matched\_filters field. I would like to add in an ability to facet on the length of the matched\_filters array and provide how many times a result matched a query. I can do the calculation within code but it would probably be faster and easier within ES. Can it give me back that info?

Thanks,

Ken

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 4, 2013, 1:01am UTC](https://discuss.elastic.co/t/named-filters-and-faceting/10220/2 "2013-01-04T01:01:49Z")

</div>

Would Filter Facets[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)work for you?

On Thursday, January 3, 2013 1:07:57 PM UTC-5, Ken Yeatman wrote:

> I've been working with Elasticsearch for the last 6 months or so and have  
> been very happy with the features and performance. However, I have run  
> into a problem I'm not sure if ES supports.
> 
> I have a web application in which users are creating multiple standing  
> queries (sometimes relatively complicated). I've been converting the  
> queries to named filters and running them with the appropriate ANDs and ORs  
> to create the result set. I can tell which result belongs to which  
> query/filter via the matched\_filters field. I would like to add in an  
> ability to facet on the length of the matched\_filters array and provide how  
> many times a result matched a query. I can do the calculation within code  
> but it would probably be faster and easier within ES. Can it give me back  
> that info?
> 
> Thanks,
> 
> Ken

--

---

<div class="post-metadata">

**Author:** ![kyeatman74](https://avatars.discourse-cdn.com/v4/letter/k/ebca7d/32.png) [@kyeatman74](https://discuss.elastic.co/u/kyeatman74)\
**Post date:** [January 4, 2013, 1:13am UTC](https://discuss.elastic.co/t/named-filters-and-faceting/10220/3 "2013-01-04T01:13:52Z")

</div>

Igor,

Yes, they would and I've been using them for a variety of other tasks. However, I can't seem to get them to reference the generated matched\_filters field rather than \_source. I haven't had time to dive into the code so I wasn't sure if it was possible or not.

Thanks,  
Ken

Ken

On Jan 3, 2013, at 8:01 PM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> Would Filter Facets work for you?
> 
> On Thursday, January 3, 2013 1:07:57 PM UTC-5, Ken Yeatman wrote:  
> I've been working with Elasticsearch for the last 6 months or so and have been very happy with the features and performance. However, I have run into a problem I'm not sure if ES supports.
> 
> I have a web application in which users are creating multiple standing queries (sometimes relatively complicated). I've been converting the queries to named filters and running them with the appropriate ANDs and ORs to create the result set. I can tell which result belongs to which query/filter via the matched\_filters field. I would like to add in an ability to facet on the length of the matched\_filters array and provide how many times a result matched a query. I can do the calculation within code but it would probably be faster and easier within ES. Can it give me back that info?
> 
> Thanks,
> 
> Ken
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 4, 2013, 1:21am UTC](https://discuss.elastic.co/t/named-filters-and-faceting/10220/4 "2013-01-04T01:21:27Z")

</div>

I don't think you can reference named filters from filter facets but you  
can simply repeat filters in the facets instead.

On Thursday, January 3, 2013 8:13:52 PM UTC-5, Ken Yeatman wrote:

> Igor,
> 
> Yes, they would and I've been using them for a variety of other tasks.  
> However, I can't seem to get them to reference the generated  
> matched\_filters field rather than \_source. I haven't had time to dive into  
> the code so I wasn't sure if it was possible or not.
> 
> Thanks,  
> Ken
> 
> Ken
> 
> On Jan 3, 2013, at 8:01 PM, Igor Motov \<[imo...@gmail.com](mailto:imo...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> Would Filter Facets[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)work for you?
> 
> On Thursday, January 3, 2013 1:07:57 PM UTC-5, Ken Yeatman wrote:
> 
> > I've been working with Elasticsearch for the last 6 months or so and have  
> > been very happy with the features and performance. However, I have run  
> > into a problem I'm not sure if ES supports.
> > 
> > I have a web application in which users are creating multiple standing  
> > queries (sometimes relatively complicated). I've been converting the  
> > queries to named filters and running them with the appropriate ANDs and ORs  
> > to create the result set. I can tell which result belongs to which  
> > query/filter via the matched\_filters field. I would like to add in an  
> > ability to facet on the length of the matched\_filters array and provide how  
> > many times a result matched a query. I can do the calculation within code  
> > but it would probably be faster and easier within ES. Can it give me back  
> > that info?
> > 
> > Thanks,
> > 
> > Ken
> 
> --

--

---

<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, 2:57am UTC](https://discuss.elastic.co/t/named-filters-and-faceting/10220/5 "2017-07-06T02:57:54Z")

</div>


