# Aggregations in ES

**URL:** <https://discuss.elastic.co/t/aggregations-in-es/3846>\
**Category:** Elasticsearch\
**Created:** [January 31, 2011, 6:38am UTC](https://discuss.elastic.co/t/aggregations-in-es/3846 "2011-01-31T06:38:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barak\_Yaish](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Barak\_Yaish](https://discuss.elastic.co/u/Barak_Yaish)\
**Post date:** [January 31, 2011, 6:38am UTC](https://discuss.elastic.co/t/aggregations-in-es/3846/1 "2011-01-31T06:38:58Z")

</div>

Hello,

I was wondering - is there a way to fetch aggregated data from ES so  
ES can be utilized for reports? For example, there is a huge index  
composed of two fields, string and some counter (the string field is  
not unique and appear more than once). I would like to sort that index  
and determine which strings has the highest counters (aggregated). One  
way would be fetching the entire index (using pagination) and  
aggregate the data on the client side, but it won't work for huge  
index (memory problems). Another way can be optimizing the index on  
build, so before inserting new data, check if data already exist in  
the index and update its counter, but index creation will be very  
slow. Is there some other way I missed?

Thanks.

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [January 31, 2011, 8:08am UTC](https://discuss.elastic.co/t/aggregations-in-es/3846/2 "2011-01-31T08:08:00Z")

</div>

Hi,

I think the easiest way for you is to use terms facet  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/facets/terms\_facet/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/facets/terms_facet/)

Regards,  
Lukas

On Mon, Jan 31, 2011 at 7:38 AM, barak [barak.yaish@gmail.com](mailto:barak.yaish@gmail.com) wrote:

> Hello,
> 
> I was wondering - is there a way to fetch aggregated data from ES so  
> ES can be utilized for reports? For example, there is a huge index  
> composed of two fields, string and some counter (the string field is  
> not unique and appear more than once). I would like to sort that index  
> and determine which strings has the highest counters (aggregated). One  
> way would be fetching the entire index (using pagination) and  
> aggregate the data on the client side, but it won't work for huge  
> index (memory problems). Another way can be optimizing the index on  
> build, so before inserting new data, check if data already exist in  
> the index and update its counter, but index creation will be very  
> slow. Is there some other way I missed?
> 
> Thanks.

---

<div class="post-metadata">

**Author:** ![Barak\_Yaish](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Barak\_Yaish](https://discuss.elastic.co/u/Barak_Yaish)\
**Post date:** [January 31, 2011, 9:19am UTC](https://discuss.elastic.co/t/aggregations-in-es/3846/3 "2011-01-31T09:19:51Z")

</div>

Thanks, few follow-up questions:

1. seems like the Facet interface does not expose the term() and  
count(), I browsed the data by casting to InternalIntTermsFacet, is it  
design decision?

2. I did get the counters ordered  
( addFacet( FacetBuilders.termsFacet("facet1").field("counter").size(1500000).order( ComparatorType.REVERSE\_TERM ) ) ),  
is there a way to fetch from the facet the associated data of the  
counter, or it requires a second fetch from the index?

Thanks.

On Jan 31, 10:08 am, Lukáš Vlček [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:

> Hi,
> 
> I think the easiest way for you is to use terms facethttp://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/facet...
> 
> Regards,  
> Lukas
> 
> On Mon, Jan 31, 2011 at 7:38 AM, barak [barak.ya...@gmail.com](mailto:barak.ya...@gmail.com) wrote:
> 
> > Hello,
> 
> > I was wondering - is there a way to fetch aggregated data from ES so  
> > ES can be utilized for reports? For example, there is a huge index  
> > composed of two fields, string and some counter (the string field is  
> > not unique and appear more than once). I would like to sort that index  
> > and determine which strings has the highest counters (aggregated). One  
> > way would be fetching the entire index (using pagination) and  
> > aggregate the data on the client side, but it won't work for huge  
> > index (memory problems). Another way can be optimizing the index on  
> > build, so before inserting new data, check if data already exist in  
> > the index and update its counter, but index creation will be very  
> > slow. Is there some other way I missed?
> 
> > Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 31, 2011, 8:03pm UTC](https://discuss.elastic.co/t/aggregations-in-es/3846/4 "2011-01-31T20:03:53Z")

</div>

On Monday, January 31, 2011 at 11:19 AM, barak wrote:

> Thanks, few follow-up questions:
> 
> 1. seems like the Facet interface does not expose the term() and  
> count(), I browsed the data by casting to InternalIntTermsFacet, is it  
> design decision?

You need to cast it to the relevant interface, for example, TermsFacet.

> 1. I did get the counters ordered  
> ( addFacet( FacetBuilders.termsFacet("facet1").field("counter").size(1500000).order( ComparatorType.REVERSE\_TERM ) ) ),  
> is there a way to fetch from the facet the associated data of the  
> counter, or it requires a second fetch from the index?

I think that what you are after is a feature other people asked for in the mailing list, which is not the count of how many times each term appeared, but more of a combination of the stats facet and terms facet. It is being worked on.

> Thanks.
> 
> On Jan 31, 10:08 am, LukÃ¡Å¡ VlÄek [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:
> 
> > Hi,
> > 
> > I think the easiest way for you is to use terms facethttp://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/facet...
> > 
> > Regards,  
> > Lukas
> > 
> > On Mon, Jan 31, 2011 at 7:38 AM, barak [barak.ya...@gmail.com](mailto:barak.ya...@gmail.com) wrote:
> > 
> > > Hello,
> > 
> > > I was wondering - is there a way to fetch aggregated data from ES so  
> > > ES can be utilized for reports? For example, there is a huge index  
> > > composed of two fields, string and some counter (the string field is  
> > > not unique and appear more than once). I would like to sort that index  
> > > and determine which strings has the highest counters (aggregated). One  
> > > way would be fetching the entire index (using pagination) and  
> > > aggregate the data on the client side, but it won't work for huge  
> > > index (memory problems). Another way can be optimizing the index on  
> > > build, so before inserting new data, check if data already exist in  
> > > the index and update its counter, but index creation will be very  
> > > slow. Is there some other way I missed?
> > 
> > > Thanks.

---

<div class="post-metadata">

**Author:** ![Barak\_Yaish](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Barak\_Yaish](https://discuss.elastic.co/u/Barak_Yaish)\
**Post date:** [February 1, 2011, 9:29am UTC](https://discuss.elastic.co/t/aggregations-in-es/3846/5 "2011-02-01T09:29:32Z")

</div>

Can you estimate when this feature will be available?

Thanks.

On Jan 31, 10:03 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> I think that what you are after is a feature other people asked for in the mailing list, which is not the count of how many times each term appeared, but more of a combination of the stats facet and terms facet. It is being worked on.

---

<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, 4:13am UTC](https://discuss.elastic.co/t/aggregations-in-es/3846/6 "2017-07-06T04:13:00Z")

</div>

Closed on July 6, 2017, 4:13am UTC


