# Divide users by the number of weekly sessions using aggregates from events\_index

**URL:** https://discuss.elastic.co/t/divide-users-by-the-number-of-weekly-sessions-using-aggregates-from-events-index/232404
**Category:** Elasticsearch
**Created:** [May 13, 2020, 9:40am UTC](https://discuss.elastic.co/t/divide-users-by-the-number-of-weekly-sessions-using-aggregates-from-events-index/232404 "2020-05-13T09:40:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Nisrein\_Sada](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nisrein_sada/32/68158_2.png) [@Nisrein\_Sada](https://discuss.elastic.co/u/Nisrein_Sada)
#### Post date: [May 13, 2020, 9:40am UTC](https://discuss.elastic.co/t/divide-users-by-the-number-of-weekly-sessions-using-aggregates-from-events-index/232404/1 "2020-05-13T09:40:49Z")

</div>

I am trying to measure the number of users into different categories based on their weekly activities by reading the events\_log\_index ES, this index has all the user interactions from a mobile. Therefore the user might have several records in the event index.

The intention is divided users into : very active users(those with more than 5 sessions weekly), mild(3 weekly sessions), inactive (\< 3 weekly sessions). So first i want to get:

1. the number of these users in each bucket, ([something similar to this] but am not sure how to implement this or what to use exactly should i group by session\_id ([Aggregation with terms and cardinality deliver different results](https://discuss.elastic.co/t/aggregation-with-terms-and-cardinality-deliver-different-results/131155)))
2. extract the users who fall in each of these categories (will i need a script to get these users or i can use the aggregates inside the query ??)

can you please provide me with an example or resource that i can use.

some of the fields in the mapping include:

- sid: session\_id
- uid: user\_id
- location: nested object containing the users country and city

```auto
    {
    "properties": {
        "city": {
            "type": "keyword"
        },
        "country_long": {
            "type": "keyword"
        },
        "country_short": {
            "type": "keyword"
        },
        "ip": {
            "type": "keyword"
        },
        "loc": {
            "type": "geo_point"
        },
        "region": {
            "type": "keyword"
        }
    }
}

```

---

<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: [June 10, 2020, 9:40am UTC](https://discuss.elastic.co/t/divide-users-by-the-number-of-weekly-sessions-using-aggregates-from-events-index/232404/2 "2020-06-10T09:40:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
