728x90
반응형

Logstash 부하로 인하여 Elastic Search에 업데이트가 안되고 있었다.

 

그래서 부랴부랴 특정 토픽들을 제외하여 급한 로그들을 처리했다.

 

그런데 일부 로그들을 파싱하는 과정에서 시간 정보를 현재 시간으로 쓰는 경우가 있었다.

 

시간 정보를 따로 갖고는 있었는데 해당 필드로 처리하고 있지 않고 있었다.

 

이것을 해결하기 위한 방법을 찾아보니 _update_by_query 를 사용하면 된다고 하여 시도해보았다.

 

처음엔 인덱스 전부를 업데이트해보았으나 너무 오래 걸렸다.

 

그래서 특정 시간대의 로그만 처리하기로 했고 다음과 같이 데이터를 보내 해결할 수 있었다.

{
  "script": {
    "lang": "painless",
    "source": "ctx._source['@timestamp'] = ctx._source.time"
  },
  "query": {
    "bool": {
        "must": [
            {
                "exists": {
                    "field": "time"
                }
            },
            {
                "range": {
                    "@timestamp": {
                        "time_zone": "+09:00",        
                        "gte": "2020-11-20T21:25:00", 
                        "lte": "2020-11-20T21:30:00"                  
                    }
                }
            }
        ]
    }
  }
}

 

참고 문헌

  1. https://stackoverflow.com/questions/55570214/how-do-i-overwrite-the-timestamp-field-with-another-field-in-elasticsearch

  2. https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html

  3. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

  4. https://www.elastic.co/guide/en/elasticsearch/reference/current/compound-queries.html

반응형

+ Recent posts