# Need help with aggregation and unique counted values

**URL:** <https://discuss.elastic.co/t/need-help-with-aggregation-and-unique-counted-values/16427>\
**Category:** Elasticsearch\
**Created:** [March 18, 2014, 1:42pm UTC](https://discuss.elastic.co/t/need-help-with-aggregation-and-unique-counted-values/16427 "2014-03-18T13:42:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Hembach](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Andreas\_Hembach](https://discuss.elastic.co/u/Andreas_Hembach)\
**Post date:** [March 18, 2014, 1:42pm UTC](https://discuss.elastic.co/t/need-help-with-aggregation-and-unique-counted-values/16427/1 "2014-03-18T13:42:24Z")

</div>

Hi all,

i'm new here and have a problem with an query. I hope someone can help me.

My Problem:

- I have a log with user clicks, the user revenue and there session id's.  
Now i want to build a data histogram with all counted clicks, the unqiue  
session ids and the user revenue.

My Query:  
{  
"query":{  
"match\_all":{}  
},  
"aggs":{  
"log\_over\_time":{  
"date\_histogram":{  
"field":"dateline",  
"interval":"month",  
"format":"yyyy-MM"  
},  
"aggs":{  
"amount":{  
"sum":{  
"field":"order\_amount"  
}  
},  
"unique":{  
"terms":{  
"field":"user\_session\_id",  
"size":100000  
}  
}  
}  
}  
}  
}

My first approach is to count the "unique" entries. But the response is  
very very large and limited to 100000 entries.

Is there a better way to do this? Can i do something like group by value?

A big thank you for the help!

Greetings,  
Andreas

--  
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/e4172503-ad5b-4bb0-9856-2fd3abb647b1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e4172503-ad5b-4bb0-9856-2fd3abb647b1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [March 18, 2014, 2:58pm UTC](https://discuss.elastic.co/t/need-help-with-aggregation-and-unique-counted-values/16427/2 "2014-03-18T14:58:37Z")

</div>

Hi,

The next version of Elasticsearch will have a new cardinality[1]  
aggregation that allows for computing unique counts. You could use it in  
lieu of the "unique" terms aggregation in order to compute the unique count  
of session IDs.

[1]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Tue, Mar 18, 2014 at 2:42 PM, Andreas Hembach [hembach3@gmail.com](mailto:hembach3@gmail.com) wrote:

> Hi all,
> 
> i'm new here and have a problem with an query. I hope someone can help me.
> 
> My Problem:
> 
> - I have a log with user clicks, the user revenue and there session id's.  
> Now i want to build a data histogram with all counted clicks, the unqiue  
> session ids and the user revenue.
> 
> My Query:  
> {  
> "query":{  
> "match\_all":{}  
> },  
> "aggs":{  
> "log\_over\_time":{  
> "date\_histogram":{  
> "field":"dateline",  
> "interval":"month",  
> "format":"yyyy-MM"  
> },  
> "aggs":{  
> "amount":{  
> "sum":{  
> "field":"order\_amount"  
> }  
> },  
> "unique":{  
> "terms":{  
> "field":"user\_session\_id",  
> "size":100000  
> }  
> }  
> }  
> }  
> }  
> }
> 
> My first approach is to count the "unique" entries. But the response is  
> very very large and limited to 100000 entries.
> 
> Is there a better way to do this? Can i do something like group by value?
> 
> A big thank you for the help!
> 
> Greetings,  
> Andreas
> 
> --  
> 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/e4172503-ad5b-4bb0-9856-2fd3abb647b1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e4172503-ad5b-4bb0-9856-2fd3abb647b1%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/e4172503-ad5b-4bb0-9856-2fd3abb647b1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/e4172503-ad5b-4bb0-9856-2fd3abb647b1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAL6Z4j5GNDsv118QRrYMc1bsBPGLG9W-XmwuDVCWsVdFPWkoHg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5GNDsv118QRrYMc1bsBPGLG9W-XmwuDVCWsVdFPWkoHg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:42am UTC](https://discuss.elastic.co/t/need-help-with-aggregation-and-unique-counted-values/16427/3 "2017-07-06T01:42:29Z")

</div>


