# Date Histogram based on aggregate total values

**URL:** <https://discuss.elastic.co/t/date-histogram-based-on-aggregate-total-values/196505>\
**Category:** Elasticsearch\
**Created:** [August 23, 2019, 11:03am UTC](https://discuss.elastic.co/t/date-histogram-based-on-aggregate-total-values/196505 "2019-08-23T11:03:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivoecpereira](https://avatars.discourse-cdn.com/v4/letter/i/5f8ce5/32.png) [@ivoecpereira](https://discuss.elastic.co/u/ivoecpereira)\
**Post date:** [August 23, 2019, 11:03am UTC](https://discuss.elastic.co/t/date-histogram-based-on-aggregate-total-values/196505/1 "2019-08-23T11:03:36Z")

</div>

Hello,

I have an index that contains documents such as the follow:

```
{
  "event" : "pageView",
  "owner" : "5dbec3a4-55bf-4c83-912e-6ddb56623bc4",
  "session" : "c17b4d6c-dfea-4ecb-8c6f-7401f8f8595a",
  "createdAt" : "2019-07-15T17:03:34Z"
}

```

I am looking to group information by each unique session UUID and after that group them into a Date Histogram per 24h.

The following query does seem to retrieve what I am looking:

```
GET events/_search?size=0&filter_path=aggregations.sessions_over_time.buckets
{
  "query": {
    "bool": {
      "filter": [{
        "term": {
          "owner.keyword": "5dbec3a4-55bf-4c83-912e-6ddb56623bc4"
        }
      }]
    }
  },
  "aggs": {
    "sessions_over_time": {
      "date_histogram": {
        "field": "createdAt",
          "interval": "24h",
          "format": "yyyy-MM-dd"
      },
      "aggs": {
        "unique_sessions": {
          "terms": {
            "field": "session.keyword"
          }
        },
        "total_sessions": {
          "sum_bucket": {
            "buckets_path": "unique_sessions>_count"
          }
        }
      }
    }
  }
}

```

However:

1. How can I retrieve only the **date intervals from histogram+total\_sessions** and not the **unique** sessions in the answer? Of course I need **unique\_sessions** to be present to be able to calculate the **total\_sessions** , but I don't need it at all in the response.

2. I should specify a size in the **unique\_sessions** term agg othersize [a default size of 10 will be used](https://github.com/elastic/elasticsearch/issues/18838) and will limit the veracity of the data, is that right? I have read that composite aggregation might help on this case as it gets the entire data being able to scroll efficiently. How could I use such agg here?

Thanks!

**EDIT:**

1. Meanwhile, I figured it out I could just use this filter\_path and that would cleanup a lot of the response for me:

If there is any other neat way to do it that would involve less processing somehow, let me know.

**The 2) point still needs some clarification however.**

---

<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:** [September 20, 2019, 11:03am UTC](https://discuss.elastic.co/t/date-histogram-based-on-aggregate-total-values/196505/2 "2019-09-20T11:03:43Z")

</div>

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