Problem with simple and composite date_histogram aggregations

(Bruno Sde Menezes) #1

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?

(Thomas Neirynck) #2

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.

(Bruno Sde Menezes) #3

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

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

Thanks