# Aggegation framework - Is there facet\_filter analogue available?

**URL:** <https://discuss.elastic.co/t/aggegation-framework-is-there-facet-filter-analogue-available/14864>\
**Category:** Elasticsearch\
**Created:** [December 14, 2013, 7:44pm UTC](https://discuss.elastic.co/t/aggegation-framework-is-there-facet-filter-analogue-available/14864 "2013-12-14T19:44:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaspars\_Sprogis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaspars_sprogis/32/1609_2.png) [@Kaspars\_Sprogis](https://discuss.elastic.co/u/Kaspars_Sprogis)\
**Post date:** [December 14, 2013, 7:44pm UTC](https://discuss.elastic.co/t/aggegation-framework-is-there-facet-filter-analogue-available/14864/1 "2013-12-14T19:44:24Z")

</div>

I just tried out new aggregation framework and wanted to see if new  
aggregation could resolve my previously discussed and unresolved problem:  
[https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/-oiL2hvjieY](https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/-oiL2hvjieY)

Since aggregation framework is planned as replacement for facets, i am  
wondering how can i filter term aggregations, without loosing actual terms,  
because as soon as i add "filter", then aggregations return only count.  
So i am looking something like "facet\_filter" for facets.  
Or this is feature is not yet developed?

Here is the mapping and sample data:

> <https://gist.github.com/darklow/7957463>

Here is query i tried:  
{  
"query": {  
"match": {  
"credits.person\_id": 1  
}  
},  
"aggs": {  
"departments": {  
"terms": {  
"field": "credits.department"  
}  
}  
},  
"size": 0  
}

Results:  
"aggregations": {  
"departments": {  
"buckets": [  
{  
"key": "producer",  
"doc\_count": 2  
},  
{  
"key": "director",  
"doc\_count": 2  
},  
{  
"key": "actor",  
"doc\_count": 2  
}  
]  
}  
}

When i tried adding filter i got following result, without ability to see  
term value:

Query:  
{  
"query": {  
"match": {  
"credits.person\_id": 1  
}  
},  
"aggs": {  
"departments": {  
"terms": {  
"field": "credits.department"  
},  
"filter": {  
"term": {  
"genre": "comedy"  
}  
}  
}  
},  
"size": 0  
}

Result:  
"aggregations": {  
"departments": {  
"doc\_count": 1  
}  
}

--  
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/f9c0b90f-8d79-4e3f-bbbf-58df4c083294%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f9c0b90f-8d79-4e3f-bbbf-58df4c083294%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 16, 2013, 12:17pm UTC](https://discuss.elastic.co/t/aggegation-framework-is-there-facet-filter-analogue-available/14864/2 "2013-12-16T12:17:26Z")

</div>

Hi,

The issue is that you are trying to define two aggregations (a terms and a  
filter) under the same name, and the aggregations framework only takes into  
account one of them. I tried to fix your last query in the following  
example: [aggs\_filter.json · GitHub](https://gist.github.com/jpountz/7986093)

On Sat, Dec 14, 2013 at 8:44 PM, Kaspars Sprogis [darklow@gmail.com](mailto:darklow@gmail.com) wrote:

> I just tried out new aggregation framework and wanted to see if new  
> aggregation could resolve my previously discussed and unresolved problem:
> 
> [Redirecting to Google Groups](https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/-oiL2hvjieY)
> 
> Since aggregation framework is planned as replacement for facets, i am  
> wondering how can i filter term aggregations, without loosing actual terms,  
> because as soon as i add "filter", then aggregations return only count.  
> So i am looking something like "facet\_filter" for facets.  
> Or this is feature is not yet developed?
> 
> Here is the mapping and sample data:  
> [Nested facets filtering by parent in ElasticSearch · GitHub](https://gist.github.com/darklow/7957463)
> 
> Here is query i tried:  
> {  
> "query": {  
> "match": {  
> "credits.person\_id": 1  
> }  
> },  
> "aggs": {  
> "departments": {  
> "terms": {  
> "field": "credits.department"  
> }  
> }  
> },  
> "size": 0  
> }
> 
> Results:  
> "aggregations": {  
> "departments": {  
> "buckets": [  
> {  
> "key": "producer",  
> "doc\_count": 2  
> },  
> {  
> "key": "director",  
> "doc\_count": 2  
> },  
> {  
> "key": "actor",  
> "doc\_count": 2  
> }  
> ]  
> }  
> }
> 
> When i tried adding filter i got following result, without ability to see  
> term value:
> 
> Query:  
> {  
> "query": {  
> "match": {  
> "credits.person\_id": 1  
> }  
> },  
> "aggs": {  
> "departments": {  
> "terms": {  
> "field": "credits.department"  
> },  
> "filter": {  
> "term": {  
> "genre": "comedy"  
> }  
> }  
> }  
> },  
> "size": 0  
> }
> 
> Result:  
> "aggregations": {  
> "departments": {  
> "doc\_count": 1  
> }  
> }
> 
> --  
> 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/f9c0b90f-8d79-4e3f-bbbf-58df4c083294%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f9c0b90f-8d79-4e3f-bbbf-58df4c083294%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Adrien Grand

--  
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/CAL6Z4j7OyVj2Ot6Crp9Eu%3DtGwht87XDtJ5oNhnkm6LRF4-dSLw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7OyVj2Ot6Crp9Eu%3DtGwht87XDtJ5oNhnkm6LRF4-dSLw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Kaspars\_Sprogis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaspars_sprogis/32/1609_2.png) [@Kaspars\_Sprogis](https://discuss.elastic.co/u/Kaspars_Sprogis)\
**Post date:** [December 16, 2013, 1:50pm UTC](https://discuss.elastic.co/t/aggegation-framework-is-there-facet-filter-analogue-available/14864/3 "2013-12-16T13:50:18Z")

</div>

Sorry, my bad, used wrong hierarchy/syntax.  
Thank you for sharing, there are very few advanced examples on new  
aggregation framework right now, so this is very helpful.

On Monday, December 16, 2013 2:17:26 PM UTC+2, Adrien Grand wrote:

> Hi,
> 
> The issue is that you are trying to define two aggregations (a terms and a  
> filter) under the same name, and the aggregations framework only takes into  
> account one of them. I tried to fix your last query in the following  
> example: [aggs\_filter.json · GitHub](https://gist.github.com/jpountz/7986093)
> 
> On Sat, Dec 14, 2013 at 8:44 PM, Kaspars Sprogis \<[dar...@gmail.com](mailto:dar...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > I just tried out new aggregation framework and wanted to see if new  
> > aggregation could resolve my previously discussed and unresolved problem:
> > 
> > [Redirecting to Google Groups](https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/-oiL2hvjieY)
> > 
> > Since aggregation framework is planned as replacement for facets, i am  
> > wondering how can i filter term aggregations, without loosing actual terms,  
> > because as soon as i add "filter", then aggregations return only count.  
> > So i am looking something like "facet\_filter" for facets.  
> > Or this is feature is not yet developed?
> > 
> > Here is the mapping and sample data:  
> > [Nested facets filtering by parent in ElasticSearch · GitHub](https://gist.github.com/darklow/7957463)
> > 
> > Here is query i tried:  
> > {  
> > "query": {  
> > "match": {  
> > "credits.person\_id": 1  
> > }  
> > },  
> > "aggs": {  
> > "departments": {  
> > "terms": {  
> > "field": "credits.department"  
> > }  
> > }  
> > },  
> > "size": 0  
> > }
> > 
> > Results:  
> > "aggregations": {  
> > "departments": {  
> > "buckets": [  
> > {  
> > "key": "producer",  
> > "doc\_count": 2  
> > },  
> > {  
> > "key": "director",  
> > "doc\_count": 2  
> > },  
> > {  
> > "key": "actor",  
> > "doc\_count": 2  
> > }  
> > ]  
> > }  
> > }
> > 
> > When i tried adding filter i got following result, without ability to see  
> > term value:
> > 
> > Query:  
> > {  
> > "query": {  
> > "match": {  
> > "credits.person\_id": 1  
> > }  
> > },  
> > "aggs": {  
> > "departments": {  
> > "terms": {  
> > "field": "credits.department"  
> > },  
> > "filter": {  
> > "term": {  
> > "genre": "comedy"  
> > }  
> > }  
> > }  
> > },  
> > "size": 0  
> > }
> > 
> > Result:  
> > "aggregations": {  
> > "departments": {  
> > "doc\_count": 1  
> > }  
> > }
> > 
> > --  
> > 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/f9c0b90f-8d79-4e3f-bbbf-58df4c083294%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f9c0b90f-8d79-4e3f-bbbf-58df4c083294%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Adrien Grand

--  
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/d3b8938d-1859-442c-a947-9baf2b405548%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d3b8938d-1859-442c-a947-9baf2b405548%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:00am UTC](https://discuss.elastic.co/t/aggegation-framework-is-there-facet-filter-analogue-available/14864/4 "2017-07-06T02:00:59Z")

</div>


