누적 합계 집계
누적 합계 집계 (Cumulative sum aggregation)
cumulative_sum 집계는 이전 집계의 버킷들에 걸쳐 누적 합계를 계산하는 부모(parent) 집계예요.
누적 합계는 주어진 수열의 부분 합들의 나열이에요. 예를 들어 수열 {a,b,c,…}의 누적 합은 a, a+b, a+b+c, …이에요. 누적 합계를 사용해 시간에 따른 필드의 변화율을 시각화할 수 있어요.
출처: 문서
본문
파라미터
cumulative_sum 집계는 다음과 같은 파라미터를 받아요.
| 파라미터 | 필수/선택 | 데이터 타입 | 설명 |
|---|---|---|---|
buckets_path |
필수 | String | 집계할 버킷의 경로예요. 버킷 경로(Buckets path) 문서를 참고하세요. |
format |
선택 | String | DecimalFormat 형식 문자열이에요. 집계의 value_as_string 속성에 형식화된 출력을 반환해요. |
예제
다음 예제는 OpenSearch Dashboards e-커머스 샘플 데이터에서 한 달 간격의 날짜 히스토그램을 생성해요. sum 하위 집계가 매월 모든 바이트의 합계를 계산해요. 마지막으로 cumulative_sum 집계가 각 월 버킷의 누적 바이트 수를 계산해요:
GET opensearch_dashboards_sample_data_logs/_search
{
"size": 0,
"aggs": {
"sales_per_month": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "month"
},
"aggs": {
"no-of-bytes": {
"sum": {
"field": "bytes"
}
},
"cumulative_bytes": {
"cumulative_sum": {
"buckets_path": "no-of-bytes"
}
}
}
}
}
}
예제 응답
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10000,
"relation": "gte"
},
"max_score": null,
"hits": []
},
"aggregations": {
"sales_per_month": {
"buckets": [
{
"key_as_string": "2025-03-01T00:00:00.000Z",
"key": 1740787200000,
"doc_count": 480,
"no-of-bytes": {
"value": 2804103
},
"cumulative_bytes": {
"value": 2804103
}
},
{
"key_as_string": "2025-04-01T00:00:00.000Z",
"key": 1743465600000,
"doc_count": 6849,
"no-of-bytes": {
"value": 39103067
},
"cumulative_bytes": {
"value": 41907170
}
},
{
"key_as_string": "2025-05-01T00:00:00.000Z",
"key": 1746057600000,
"doc_count": 6745,
"no-of-bytes": {
"value": 37818519
},
"cumulative_bytes": {
"value": 79725689
}
}
]
}
}
}