# Calculating terms\_stats for entire key\_feild?

**URL:** <https://discuss.elastic.co/t/calculating-terms-stats-for-entire-key-feild/8960>\
**Category:** Elasticsearch\
**Created:** [September 8, 2012, 4:54pm UTC](https://discuss.elastic.co/t/calculating-terms-stats-for-entire-key-feild/8960 "2012-09-08T16:54:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rio/32/2728_2.png) [@Rio](https://discuss.elastic.co/u/Rio)\
**Post date:** [September 8, 2012, 4:54pm UTC](https://discuss.elastic.co/t/calculating-terms-stats-for-entire-key-feild/8960/1 "2012-09-08T16:54:18Z")

</div>

Hi,

I was wondering if there was a way to calculating terms\_stats for entire  
key\_field, not the terms within it.

For a simplified example, let's say I had these Article records:

[  
{author: "Red Wolf", title: "Bread Roll", readers: 10}  
{author: "Blue Wolf", title: "Bread Stick", readers: 10}  
{author: "Red Wolf", title: "Sheep Skin", readers: 10}  
{author: "Green Wolf", title: "Sheep Wool", readers: 10}  
{author: "Bear", title: "Sheep Bread", readers: 10}  
]

I'd like to calculate the stats for "Red Wolf", but with the following, I'd  
get the terms like: ['red', 'wolf', 'blue', 'green', 'bear']

{  
"query" : {  
"match\_all" : { }  
},  
"facets" : {  
"author\_reader\_stats" : {  
"terms\_stats" : {  
"key\_field" : "author",  
"value\_field" : "readers"  
}  
}  
}  
}

I tried a variety of analyzers and some custom analyzers on the author  
field, including not\_analyzed, without luck.

Anyone have any suggestions?

Thanks sooo much!

-Rio

--

---

<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:13am UTC](https://discuss.elastic.co/t/calculating-terms-stats-for-entire-key-feild/8960/2 "2017-07-06T03:13:35Z")

</div>


