Bucket Aggregation Query inside Composite Aggregation giving wrong answer

I am using elastic version 6.2.4 , and my document looks like this

[
  {
    "viewingSessionId": "7484954c-1b4b-40b1-8557-4eccf1515691_0",
    "browserType": "Chrome",
    "programId": "program:703",
    "sessionStartTime": 1571659315324
  },
  {
    "viewingSessionId": "2b1de0f4-cd7a-4a35-9216-ec9c0b4d544e_0",
    "browserType": "Firefox",
    "programId": "program:703",
    "sessionStartTime": 1571659470424
  },
  {
    "viewingSessionId": "88cfaf6f-5758-4c97-b5c6-a9cdfd10114d_0",
    "browserType": "Firefox",
    "programId": "program:703",
    "sessionStartTime": 1571661648148
  },
  {
    "viewingSessionId": "9572eb0d-f5b9-4ce6-b64a-6399b317b0bb_0",
    "browserType": "Firefox",
    "programId": "program:703",
    "sessionStartTime": 1571663894918
  }
]

I am using composite aggregation to build aggregated index which will hold daily viewcount and browsercount for each programId

{
  "size": 0,
  "query": {
    "bool": {
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "aggregations": {
    "viewstats_over_time": {
      "composite": {
        "size": 50,
        "sources": [
          {
            "viewstats_over_time": {
              "date_histogram": {
                "field": "sessionStartTime",
                "value_type": "date",
                "interval": "1d"
              }
            }
          },
          {
            "by_program": {
              "terms": {
                "field": "programId"
              }
            }
          }
        ]
      },
      "aggs": {
        "byBrowserType": {
          "terms": {
            "field": "browserType"
          }
        }
      }
    }
  }
}

This query is returning the following result which is wrong

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 4,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "viewstats_over_time": {
      "buckets": [
        {
          "key": {
            "viewstats_over_time": 1571616000000,
            "by_program": "program:703"
          },
          "doc_count": 4,
          "byBrowserType": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
              {
                "key": "Chrome",
                "doc_count": 4
              }
            ]
          }
        }
      ]
    }
  }
}

As per the docs bucket aggregation is possible as a sub-aggregation to composite aggregation

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