키보드워리어

[ELK] Collection Time 작업 본문

ELK

[ELK] Collection Time 작업

꽉 쥔 주먹속에 안경닦이 2023. 11. 23. 12:59
728x90

쿼리-범위-colletionTime

 

Range query | Elasticsearch Guide [8.11] | Elastic

The time_zone parameter does not affect the date math value of now. now is always the current system time in UTC. However, the time_zone parameter does convert dates calculated using now and date math rounding. For example, the time_zone parameter will con

www.elastic.co

날짜 수학

 

Date math expressions | Elasticsearch .NET Clients [7.17] | Elastic

Date math expressionsedit The date type supports using date math expression when using it in a query/filter Whenever durations need to be specified, eg for a timeout parameter, the duration can be specified The expression starts with an "anchor" date, whic

www.elastic.co

엘라스틱에서 제공해주는 시간 날짜 계산 방법.

 

핵심내용은 다음과 같다.

The time_zone parameter does not affect the date math value of now. now is always the current system time in UTC.

'time_zone' 매개 변수는 [date math]('now' 값)에 영향을 주지 않습니다.
'now'는 UTC에서 항상 현재 시스템 시간입니다.

However, the time_zone parameter does convert dates calculated using now and date math rounding. For example, the time_zone parameter will convert a value of now/d.

하지만 time_zone 매개 변수는 now와 date math 반올림을 사용하여 계산한 날짜를 변환합니다.
예를 들어 time_zone 매개 변수는 now/d 값을 변환합니다.


문제 쿼리

#case1
GET example/_count
{
    "query": {
        "range": {
            "collectionTime":{
                "gte": "17/11/2023 11:00",
                "lte": "17/11/2023 11:30",
                "format": "dd/MM/yyyy HH:mm"
            }
        }
    }
}
#case2
GET example/_search
{
    "sort": [
        {
            "collectionTime": {
                "order": "asc"
            }
        }
    ],
    "query": {
        "range": {
            "collectionTime": {
                "time_zone": "UTC+09:00",
                "gte": "now/h",
                "lte": "now/h+30m",
                "format": "dd/MM/yyyy HH:mm || YYYY-MM-dd"                
            }
        }
    }
}

case1의 경우 명시적으로 범위를 날짜로 적은 경우 count값 52개 발생한다.

case2의 경우 현재 시간 기준 정시부터 정시 30분까지 지정하고 검색해보면 hits.total.value의 값은 0이 된다.

 

핵심 내용을 읽어봤다면 쉽게 문제를 풀 수 있다.

정답

GET example/_search
{
    "sort": [
        {
            "collectionTime": {
                "order": "asc"
            }
        }
    ],
    "query": {
        "range": {
            "collectionTime": {                
                "gte": "now/h+9h",
                "lte": "now/h+9h+30m",
                "format": "dd/MM/yyyy HH:mm || YYYY-MM-dd",
                "time_zone": "UTC+09:00"              
            }
        }
    }
}

#now는 무조건 UTC 기준이다.
#time_zone은 now에 영향을 주지 않는다

 

728x90

'ELK' 카테고리의 다른 글

[ELK] ML 학습해보기  (2) 2023.10.29
[ELK] JSON 데이터를 파이썬으로 파싱 후 적재해보자.  (1) 2023.10.27
[ELK]logstash란?  (0) 2023.10.20
[ELK] 키바나 시각화  (2) 2023.10.09
[ELK] kafka, filebeats 어떻게 설치할까?  (0) 2023.10.01