# Problem with simple and composite date\_histogram aggregations

**URL:** https://discuss.elastic.co/t/problem-with-simple-and-composite-date-histogram-aggregations/181264
**Category:** Kibana
**Created:** [May 15, 2019, 7:36pm UTC](https://discuss.elastic.co/t/problem-with-simple-and-composite-date-histogram-aggregations/181264 "2019-05-15T19:36:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BrunoSdeMenezes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brunosdemenezes/32/46413_2.png) [@BrunoSdeMenezes](https://discuss.elastic.co/u/BrunoSdeMenezes)
#### Post date: [May 15, 2019, 7:36pm UTC](https://discuss.elastic.co/t/problem-with-simple-and-composite-date-histogram-aggregations/181264/1 "2019-05-15T19:36:39Z")

</div>

Hello there,

I'm using Elastic querys to build vega plots on Kibana, but I'm having problems with date\_histogram.

When I do a simple query to build a simple histogram, the query works fine:

```
GET trabalhista*/_search
{
  "aggs": {
          "processos_ano": {
            "date_histogram": {
              "field": "data_registrado_contrato",
              "interval": "year"
            }
          }
        },
        "size": 0
}

```

The results are right: 6 years (2014 - 2019)

```
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1499,
    "max_score" : 0.0,
    "hits" : []
  },
  "aggregations" : {
    "processos_ano" : {
      "buckets" : [
        {
          "key_as_string" : "2014-01-01T00:00:00.000Z",
          "key" : 1388534400000,
          "doc_count" : 275
        },
        {
          "key_as_string" : "2015-01-01T00:00:00.000Z",
          "key" : 1420070400000,
          "doc_count" : 279
        },
        {
          "key_as_string" : "2016-01-01T00:00:00.000Z",
          "key" : 1451606400000,
          "doc_count" : 276
        },
        {
          "key_as_string" : "2017-01-01T00:00:00.000Z",
          "key" : 1483228800000,
          "doc_count" : 292
        },
        {
          "key_as_string" : "2018-01-01T00:00:00.000Z",
          "key" : 1514764800000,
          "doc_count" : 276
        },
        {
          "key_as_string" : "2019-01-01T00:00:00.000Z",
          "key" : 1546300800000,
          "doc_count" : 101
        }
      ]
    }
  }
}

```

But when I put this query on a composite query, I only get two years instead of 6:

```
GET trabalhista*/_search
{
  "aggs": {
    "meus_buckets": {
      "composite": {
        "sources": [
          {
            "processos_ano": {
              "date_histogram": {
                "field": "data_registrado_contrato",
                "interval":"year"
              }
            }
          },
          {
            "diretoria": {
              "terms": {
                "field": "diretoria.keyword"
              }
            }
          }
        ]
      }
    }
  }
}

```

And the result:

```
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1499,
    "max_score" : 0.0,
    "hits" : []
  },
  "aggregations" : {
    "meus_buckets" : {
      "after_key" : {
        "processos_ano" : 1420070400000,
        "diretoria" : "Outras"
      },
      "buckets" : [
        {
          "key" : {
            "processos_ano" : 1388534400000,
            "diretoria" : "Comercial"
          },
          "doc_count" : 42
        },
        {
          "key" : {
            "processos_ano" : 1388534400000,
            "diretoria" : "Demanda"
          },
          "doc_count" : 56
        },
        {
          "key" : {
            "processos_ano" : 1388534400000,
            "diretoria" : "Industrial"
          },
          "doc_count" : 41
        },
        {
          "key" : {
            "processos_ano" : 1388534400000,
            "diretoria" : "Outras"
          },
          "doc_count" : 41
        },
        {
          "key" : {
            "processos_ano" : 1388534400000,
            "diretoria" : "Provisão"
          },
          "doc_count" : 46
        },
        {
          "key" : {
            "processos_ano" : 1388534400000,
            "diretoria" : "Terceiros"
          },
          "doc_count" : 49
        },
        {
          "key" : {
            "processos_ano" : 1420070400000,
            "diretoria" : "Comercial"
          },
          "doc_count" : 46
        },
        {
          "key" : {
            "processos_ano" : 1420070400000,
            "diretoria" : "Demanda"
          },
          "doc_count" : 45
        },
        {
          "key" : {
            "processos_ano" : 1420070400000,
            "diretoria" : "Industrial"
          },
          "doc_count" : 53
        },
        {
          "key" : {
            "processos_ano" : 1420070400000,
            "diretoria" : "Outras"
          },
          "doc_count" : 40
        }
      ]
    }
  }
}

```

Can someone tell me what I'm doing wrong?

---

<div class="post-metadata">

### Author: ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)
#### Post date: [May 16, 2019, 5:49pm UTC](https://discuss.elastic.co/t/problem-with-simple-and-composite-date-histogram-aggregations/181264/2 "2019-05-16T17:49:06Z")

</div>

Is there a particular reason you are trying to use the composite-aggregation?

That one is generally used to page through large resultsets, something which Vega does not support.

---

<div class="post-metadata">

### Author: ![BrunoSdeMenezes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brunosdemenezes/32/46413_2.png) [@BrunoSdeMenezes](https://discuss.elastic.co/u/BrunoSdeMenezes)
#### Post date: [May 16, 2019, 7:56pm UTC](https://discuss.elastic.co/t/problem-with-simple-and-composite-date-histogram-aggregations/181264/3 "2019-05-16T19:56:11Z")

</div>

I'm building a plot on Vega-lite...

But I've resolved the issue, using size on composite terms works fine...

Thanks

---

<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 13, 2019, 7:56pm UTC](https://discuss.elastic.co/t/problem-with-simple-and-composite-date-histogram-aggregations/181264/4 "2019-06-13T19:56:12Z")

</div>

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