Increase doc_count even if record is same in date_histogram on Array field

I have an object / array field which contains date-time. This field contains every second of the duration between start and end time of some event. I am doing this because I want to see the running events on each second. So my field me look like this,

{
  "_index" : "timeline",
  "_id" : "GGWGB4cBU8qsnVUf4m44",
  "fields" : {
    "upTimeArr" : [
      "1679458442000",
      "1679458443000",
      "1679458444000",
      "1679458445000",
      "1679458446000",
      "1679458447000",
      "1679458448000",
      "1679458449000",
      "1679458450000",
      "1679458451000",
      "1679458452000",
      "1679458453000",
      "1679458454000",
      "1679458455000"
    ]
  }
}

Now, if I will run a date_histogram aggregation with fixed_interval as "01s"

GET timeline/_search
{
  "aggs": {
    "0": {
     "date_histogram": {
            "field": "upTimeArr",
            "fixed_interval": "01s",
            "time_zone": "Asia/Calcutta",
            "min_doc_count": 1
          }
    }
  },
  
  "size": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "_id": "GGWGB4cBU8qsnVUf4m44"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

then my result will be something like this,

"buckets" : [
        {
          "key" : 1679458442000,
          "doc_count" : 1
        },
        {
          "key" : 1679458443000,
          "doc_count" : 1
        },
        {
          "key" : 1679458444000,
          "doc_count" : 1
        },
        {
          "key" : 1679458445000,
          "doc_count" : 1
        },
        {
          "key" : 1679458446000,
          "doc_count" : 1
        },
        {
          "key" : 1679458447000,
          "doc_count" : 1
        },
        {
          "key" : 1679458448000,
          "doc_count" : 1
        },
        {
          "key" : 1679458449000,
          "doc_count" : 1
        },
        {
          "key" : 1679458450000,
          "doc_count" : 1
        },
        {
          "key" : 1679458451000,
          "doc_count" : 1
        },
        {
          "key" : 1679458452000,
          "doc_count" : 1
        },
        {
          "key" : 1679458453000,
          "doc_count" : 1
        },
        {
          "key" : 1679458454000,
          "doc_count" : 1
        },
        {
          "key" : 1679458455000,
          "doc_count" : 1
        }
      ]

( I have removed "key_as_string" from the result )

But if I will set fixed_interval as 10 secs

"fixed_interval": "10s"

then the result will be,

"buckets" : [
  {
    "key" : 1679458440000,
    "doc_count" : 1
  },
  {
    "key" : 1679458450000,
    "doc_count" : 1
  },
  {
    "key" : 1679458460000,
    "doc_count" : 1
  }
]

In all the above cases "doc_count" is 1 for each bucket which is correct because document is actually just one. But in my case, if I the fixed_interval is 10s then there should be some count which can represent the contribution of each member of the "upTimeArr" field.

I am expecting the result something like this,

"buckets" : [
  {
    "key" : 1679458440000,
    "count" : 8
  },
  {
    "key" : 1679458450000,
    "count" : 6
  }
]

Is it possible to achieve this?

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