# Can Kibana group events around a common id and perform statistics on the group, then plot it?

**URL:** <https://discuss.elastic.co/t/can-kibana-group-events-around-a-common-id-and-perform-statistics-on-the-group-then-plot-it/345613>\
**Category:** Kibana\
**Created:** [October 24, 2023, 7:32am UTC](https://discuss.elastic.co/t/can-kibana-group-events-around-a-common-id-and-perform-statistics-on-the-group-then-plot-it/345613 "2023-10-24T07:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wpq](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@Wpq](https://discuss.elastic.co/u/Wpq)\
**Post date:** [October 24, 2023, 7:32am UTC](https://discuss.elastic.co/t/can-kibana-group-events-around-a-common-id-and-perform-statistics-on-the-group-then-plot-it/345613/1 "2023-10-24T07:32:12Z")

</div>

I usually use Kibana (as a basic user) with a flow of **independent** timed events. I then make some graphs on the evolution or statistics of a population in a specific timeframe.

I now face a problem I do not know how to approach: a set of timed events, but with a common identifier and a common date that groups them into clusters and I would like to make statistics on these clusters.

To take an example, consider the following set of data ("some date" is a random date)

```json
[
    {
        "id": 1,
        "age": 20,
        "nice": true,
        "sent": "date1"
    },
    {
        "id": 1,
        "age": 25,
        "nice": false,
        "sent": "date1"
    },
    {
        "id": 2,
        "age": 20,
        "nice": false,
        "sent": "date2"
    },
    {
        "id": 2,
        "age": 30,
        "nice": false,
        "sent": "date2"
    }
]

```

My goal is to have an evolution of the average of "nice" people by `id` (or by `sent`). This requires to first group the data by `id`, then to calculate the average by group, and then to plot this average over time (the group is located at `sent`).

Is Kibana able to do something like that?

My backup plan is to mak the calculations upstream and sent the results to Kibana but I would like to avoid this because I may want to show some other statistics (say, the median instead of the average - this will require all data to be updated in Kibana from the upstream backend)

---

<div class="post-metadata">

**Author:** ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)\
**Post date:** [October 27, 2023, 9:23am UTC](https://discuss.elastic.co/t/can-kibana-group-events-around-a-common-id-and-perform-statistics-on-the-group-then-plot-it/345613/2 "2023-10-27T09:23:43Z")

</div>

In Lens you can break your chart by `id` and chart over time (`sent`) any metric (`median`, `average`, etc) and include filters to only render the data you want.

I've created an index and the associated Data View with some data following your spec:

```auto
DELETE discuss-345613

PUT discuss-345613
{
  "mappings": {
    "properties": {
      "id": {"type": "keyword"},
      "age": {"type": "integer"},
      "nice": {"type": "boolean"},
      "sent": {"type": "date"}
    }
  }
}

# 10-24
POST discuss-345613/_bulk
{ "index": {} }
{ "id": 1, "age": 20, "nice": true, "sent": "2023-10-24"}
{ "index": {} }
{ "id": 1, "age": 25, "nice": false, "sent": "2023-10-24"}
{ "index": {} }
{ "id": 2, "age": 20, "nice": true, "sent": "2023-10-24"}
{ "index": {} }

# 10-25
POST discuss-345613/_bulk
{ "index": {} }
{ "id": 1, "age": 20, "nice": true, "sent": "2023-10-25"}
{ "index": {} }
{ "id": 1, "age": 30, "nice": false, "sent": "2023-10-25"}
{ "index": {} }
{ "id": 2, "age": 20, "nice": true, "sent": "2023-10-25"}
{ "index": {} }
{ "id": 2, "age": 30, "nice": false, "sent": "2023-10-25"}
{ "index": {} }
{ "id": 3, "age": 30, "nice": true, "sent": "2023-10-25"}

# 10-26
POST discuss-345613/_bulk
{ "index": {} }
{ "id":1, "age": 25, "nice": true, "sent": "2023-10-26"}
{ "index": {} }
{ "id": 2, "age": 35, "nice": true, "sent": "2023-10-26"}
{ "index": {} }
{ "id":2, "age": 23, "nice": true, "sent": "2023-10-26"}
{ "index": {} }
{ "id": 3, "age": 35, "nice": true, "sent": "2023-10-26"}
{ "index": {} }
{ "id":3, "age": 20, "nice": true, "sent": "2023-10-26"}
{ "index": {} }
{ "id": 3, "age": 35, "nice": true, "sent": "2023-10-26"}

# Data view using sent as time field
POST kbn:/api/data_views/data_view
{
  "data_view": {
    "title": "discuss-345613",
    "timeFieldName": "sent"
  }
}

```

Then, in Lens, it is straightforward to add a filter for `nice: true` and a breakdown for the top 10 values of `id` (you can also use intervals or any other filter).

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/d/bd269f02c07284cbfcbca86a5a128c3e85a2dabc.png)

---

<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:** [November 24, 2023, 9:23am UTC](https://discuss.elastic.co/t/can-kibana-group-events-around-a-common-id-and-perform-statistics-on-the-group-then-plot-it/345613/3 "2023-11-24T09:23:51Z")

</div>

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