# Compare aggregation result in Elastic Search to find repetitive users

**URL:** https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471
**Category:** Elasticsearch
**Created:** [July 14, 2016, 5:32am UTC](https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471 "2016-07-14T05:32:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sa35t](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sa35t](https://discuss.elastic.co/u/sa35t)
#### Post date: [July 14, 2016, 5:32am UTC](https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471/1 "2016-07-14T05:32:02Z")

</div>

Hi,

Basically I want to do something like this [http://stackoverflow.com/questions/36711667/comparing-data-in-kibana](http://stackoverflow.com/questions/36711667/comparing-data-in-kibana)

Currently I can find unique users with in data range, but how do I compare it with my whole corpus to find how many of them are new and how many of them repetitive. Current query to find unique user with in time range

`{ "from": 0, "size": 0, "query": { "filtered": { "query": { "query_string": { "analyze_wildcard": true, "query": "*" } }, "filter": { "bool": { "must": [{ "range": { "date_time": { "lte": 1468348199000, "format": "epoch_millis", "gte": 1468261800000 } } }], "must_not": [] } } } }, "aggs": { "cardinality_device_id": { "terms": { "field": "device_id" } } }, "fields": ["*", "_source"] }`

Any help will be appreciated. Thanks

---

<div class="post-metadata">

### Author: ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)
#### Post date: [August 9, 2016, 10:13am UTC](https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471/2 "2016-08-09T10:13:58Z")

</div>

Hi,

I think it is hard to calculate in Elasticsearch only.  
You get terms aggs twice, one is total one is a day.  
Then you compare these data on your familiar programing language.  
It is easy way to do this.

---

<div class="post-metadata">

### Author: ![sa35t](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sa35t](https://discuss.elastic.co/u/sa35t)
#### Post date: [August 14, 2016, 8:39am UTC](https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471/3 "2016-08-14T08:39:47Z")

</div>

What if data set is too large ?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [August 14, 2016, 9:27am UTC](https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471/4 "2016-08-14T09:27:55Z")

</div>

One way to perform this type of user centric analysis is to create a separate [entity-centric index](https://www.elastic.co/elasticon/2015/sf/building-entity-centric-indexes). This allows you to spread out the computation and prepare the data over time rather than do it all at query time, which can be expensive and complicated. If designed correctly it should also be possible to use this entity-centric index directly in Kibana, and as it will contained summarised and aggregated information it will generally perform and scale quite well.

---

<div class="post-metadata">

### Author: ![taras](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taras/32/507_2.png) [@taras](https://discuss.elastic.co/u/taras)
#### Post date: [August 14, 2016, 7:43pm UTC](https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471/5 "2016-08-14T19:43:46Z")

</div>

Depending on the scale of your problem. Lets say you're talking RTB scale, then entity centric indexes and some batch processing are your main options.

For processing billions of signals we have the following rough breakdown:

- Trail Collection (Audit log) with raw data and minimal indexed fields
- CurrentProfile - a sliding time window index with verbose aggregation of pretty much everything we _may_ care about
- DeviceIdMapping - ID to ID mapping. Gives you cheap existence check among other things.
- Profile - That is your longer lived

* * *

If you have your profile object index then you can query & aggregate by creation timestamp, last action timestamp, whatever makes sense to the app

---

<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 5, 2017, 10:27pm UTC](https://discuss.elastic.co/t/compare-aggregation-result-in-elastic-search-to-find-repetitive-users/55471/6 "2017-07-05T22:27:51Z")

</div>


