# Aggregation with Concatenation

**URL:** <https://discuss.elastic.co/t/aggregation-with-concatenation/373526>\
**Category:** Elasticsearch\
**Tags:** aggregations\
**Created:** [January 22, 2025, 4:34pm UTC](https://discuss.elastic.co/t/aggregation-with-concatenation/373526 "2025-01-22T16:34:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdwolf](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@kdwolf](https://discuss.elastic.co/u/kdwolf)\
**Post date:** [January 22, 2025, 4:34pm UTC](https://discuss.elastic.co/t/aggregation-with-concatenation/373526/1 "2025-01-22T16:34:42Z")

</div>

I have an index (see below) which stores RTT (Realtime Text) - every time someone types a letter within a conversation, it is stored as a document as a "typed" event. If someone deletes the letter, it will be stored as a document with "deleted" event. When the user sends the message to another user - it will be stored as "pressed" event.  
My use case is to present the conversation to the end-user in a readable format. for example querying the documents, provided below should return "Hello" for User1 and "Hi" for User2 with the respective time, when each started their conversation. I believe I can do it quite quickly in SQL DBs, but I do not have sufficient experience to do it using Elasticsearch - any help will be truly appreciated.

```auto
POST /recorded-rtt-index/_doc
{
  "docs": [
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:00Z",
      "user": "User1",
      "event": "typed",
      "character": "H"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:01Z",
      "user": "User1",
      "event": "typed",
      "character": "e"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:02Z",
      "user": "User1",
      "event": "typed",
      "character": "l"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:02Z",
      "user": "User1",
      "event": "typed",
      "character": "l"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:03Z",
      "user": "User1",
      "event": "typed",
      "character": "o"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:03Z",
      "user": "User1",
      "event": "pressed",
      "key": "Enter"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:04Z",
      "user": "User2",
      "event": "typed",
      "character": "H"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:05Z",
      "user": "User2",
      "event": "typed",
      "character": "e"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:06Z",
      "user": "User2",
      "event": "typed",
      "character": "l"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:07Z",
      "user": "User2",
      "event": "deleted",
      "character": "l"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:08Z",
      "user": "User2",
      "event": "deleted",
      "character": "e"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:08Z",
      "user": "User2",
      "event": "typed",
      "character": "i"
    },
    {
      "textSessionId": "9c3321f0-34f9-ed11-907c-000d3a3a4d73",
      "timeStamp": "2025-01-22T14:00:09Z",
      "user": "User2",
      "event": "pressed",
      "key": "Enter"
    }
  ]
}

```
