QUERY
GET my_index/_search
{
"aggs": {
"byDate": {
"date_range": {
"field": "createdAt",
"ranges": [
{"from": "now-1w", "to": "now", "key": "week" },
{"from": "now-1d", "to": "now", "key": "today"}
],
"keyed": true // 키 네이밍을 가능하게 해줌
}
}
}
}
RESPONSE
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 14,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"byDate" : {
"buckets" : {
"week" : {
"from" : 1.665159166158E12,
"from_as_string" : "2022-10-07T16:12:46.158Z",
"to" : 1.665763966158E12,
"to_as_string" : "2022-10-14T16:12:46.158Z",
"doc_count" : 14
},
"today" : {
"from" : 1.665677566158E12,
"from_as_string" : "2022-10-13T16:12:46.158Z",
"to" : 1.665763966158E12,
"to_as_string" : "2022-10-14T16:12:46.158Z",
"doc_count" : 3
}
}
}
}
}