개요

회사에서 ES로 통계 시스템을 만들고 있다. 이 때 월별 지표를 뽑아낼 일이 있었는데 ES지표를 UTC 기준으로 쌓아놨는데

기본 date_histogram으로 Aggr을 하면 월별 데이터가 한국 기준 GMT +9와 다르게 집계되는것을 발견하였다.

그래서 해결 방법을 모색 후 포스팅 한다.

해결방법

GET /index/type/_search
{
  "aggs": {
    "monthly": {
      "date_histogram": {
    "field": "ts",
    "interval": "month",
    "time_zone": "+09:00"
      }
    }
  }
}

Reference

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html