3

I'm trying to do this aggregation:

"aggs":{
    "visits_by_hour":{
        "date_histogram":{
            "field": "acctstarttime",
            "interval":"hour",
            "format": "HH",
            "min_doc_count": 0
        }
    }
}

It works perfectly but I need to group by hour and do not return multiple hours for the same hour, is that make any sense? This is what I'm getting now:

{
      "key_as_string": "12",
      "key": 1440244800000,
      "doc_count": 18
},
{
      "key_as_string": "12",
      "key": 1440331200000,
      "doc_count": 17
}

This is what I need (grouped by hour):

 {
      "key_as_string": "12",
      "key": 1440331200000,
      "doc_count": 35
 }

Suggestions?

EDIT

I've found a solution for that problem. Not sure if is the best approach, but it works.

"aggs": {
    "hour": {
        "terms": {
            "script": "doc['acctstarttime'].date.hourOfDay"
        }
    }
}

0 Answers0