# Using terms\_stats facet with Filter Facets to get "mean" value along with "count"

**URL:** <https://discuss.elastic.co/t/using-terms-stats-facet-with-filter-facets-to-get-mean-value-along-with-count/9485>\
**Category:** Elasticsearch\
**Created:** [October 27, 2012, 6:19pm UTC](https://discuss.elastic.co/t/using-terms-stats-facet-with-filter-facets-to-get-mean-value-along-with-count/9485 "2012-10-27T18:19:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![revdev](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@revdev](https://discuss.elastic.co/u/revdev)\
**Post date:** [October 27, 2012, 6:19pm UTC](https://discuss.elastic.co/t/using-terms-stats-facet-with-filter-facets-to-get-mean-value-along-with-count/9485/1 "2012-10-27T18:19:39Z")

</div>

When I use filter facet[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html) with  
terms\_stats facet, I get just counts. Is there anyway, I can apply  
filters/query to terms\_stats facet and get other metrics like "total",  
"mean", "min", "max" etc?  
Thanks!

--

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [October 27, 2012, 6:25pm UTC](https://discuss.elastic.co/t/using-terms-stats-facet-with-filter-facets-to-get-mean-value-along-with-count/9485/2 "2012-10-27T18:25:14Z")

</div>

Hello!

You can include filters in your facets calculation, for example like this:

{

"query" : {

"match\_all" : {}

},

"facets" : {

"facet1" : {

"terms" : {

```
"field" : "tags"

```

},

"facet\_filter" : {

```
"term" : {

 "category" : "books"

}

```

}

}

}

}

More about this can be found here: [http://www.elasticsearch.org/guide/reference/api/search/facets/](http://www.elasticsearch.org/guide/reference/api/search/facets/)

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

When I use [filter facet](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html) with terms\_stats facet, I get just counts. Is there anyway, I can apply filters/query to terms\_stats facet and get other metrics like "total", "mean", "min", "max" etc?

Thanks!

--

---

<div class="post-metadata">

**Author:** ![revdev](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@revdev](https://discuss.elastic.co/u/revdev)\
**Post date:** [October 27, 2012, 6:29pm UTC](https://discuss.elastic.co/t/using-terms-stats-facet-with-filter-facets-to-get-mean-value-along-with-count/9485/3 "2012-10-27T18:29:32Z")

</div>

oops, I was using just "filter" rather than "facet\_filter" . doh!  
Thanks for pointing that out. Elasticsearch is way complicated for my  
little brain. 🙂

On Saturday, October 27, 2012 11:25:28 AM UTC-7, Rafał Kuć wrote:

> Hello!
> 
> You can include filters in your facets calculation, for example like this:
> 
> {  
> "query" : {  
> "match\_all" : {}  
> },  
> "facets" : {  
> "facet1" : {  
> "terms" : {  
> "field" : "tags"  
> },  
> "facet\_filter" : {  
> "term" : {  
> "category" : "books"  
> }  
> }  
> }  
> }  
> }
> 
> More about this can be found here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/)
> 
> \*--  
> Regards,  
> Rafał Kuć  
> Sematext :: _[http://sematext.com/](http://sematext.com/)_ :: Solr - Lucene - Nutch -  
> Elasticsearch
> 
> - 
> 
> When I use filter facet[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html) with  
> terms\_stats facet, I get just counts. Is there anyway, I can apply  
> filters/query to terms\_stats facet and get other metrics like "total",  
> "mean", "min", "max" etc?  
> Thanks!
> 
> --

--

---

<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:07am UTC](https://discuss.elastic.co/t/using-terms-stats-facet-with-filter-facets-to-get-mean-value-along-with-count/9485/4 "2017-07-06T03:07:00Z")

</div>

Closed on July 6, 2017, 3:07am UTC


