I am trying to count distinct date in a field so I followed the cardinality aggregation to do it but it failed to return the expected result, any suggestion on what I am doing wrong please?
{
"query": {
"bool": {
"filter": [
{"term": { "Id": "793"} },
{"range": {
"starttime": {
"gte": "2019-08-12T11:20:00",
"lte": "2019-08-12T11:30:00"
}
} }
]
}
},
"aggs": {
"sessions": {
"terms" : { "field" : "stationid" },
"aggs": {
"total_minute": {
"sum": {"script":"doc['stoptime'].date.getMillis() - doc['starttime'].date.getMillis()"}
}
}
} ,
"count_starttime": {
"cardinality" :
{"script":"doc['starttime'].date.dayOfMonth"}
}
}
}