[Elasticsearch] Deep Pagination.

Elastic/Elasticsearch 2021. 10. 18. 10:43

Elasticsearch 레퍼런스 문서 입니다.

 

https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
Deep pagination 기능 구현을 위해서는 Scroll API 를 더 이상 추천 하지 않습니다.
search_after API 를 이용해서 구현 하는 것을 추천 합니다.

Scroll API 는 실시간 서비스를 위한 용도가 아니며, 전체 데이터(대용량 데이터)에 대한 재색인 또는 재구성을 위한 용도로 사용을 합니다.

 

scroll 보다는 search_after 를 사용하라고 하고 있으며, 두 API 모두 전체 또는 특정 질의 조건에 따라 탐색 및 페이징 처리가 가능 합니다.

 

단, 이 기능을 사용 하실 경우

- Cluster 내 Node 의 자원이 충분한지 확인 하시고

- 실시간 서비스 용도로 사용을 하지 마시고

- 색인 요청은 없는지도 확인 하시고

사용 하시길 추천 드립니다.

:

[Logstash] Event, Fields 데이터 사용방법

Elastic/Logstash 2021. 10. 7. 19:40

logstash 사용 시 event, fields 데이터 사용방법에 대한 공홈 레퍼런스 문서 입니다.
처음 사용하시는 분들에게는 유용한 자료라고 생각 되어서 공유 합니다.

https://www.elastic.co/guide/en/logstash/current/event-api.html
https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html

:

[Filebeat] ignore_older 와 tail_files 관련.

Elastic/Beats 2021. 10. 7. 19:08

이 두 설정은 같이 고려 하는게 좋습니다.

각 설정은 아래 공홈 문서 참고 하시면 됩니다.

 

https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#filebeat-input-log-ignore-older

https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#_tail_files_3

 

[Case 1] filebeat 재시작 시 데이터 유실 없이 사용하기 위한 설정

filebeat.inputs:
- type: log
...중략...
  ignore_older: 0
  tail_files: false
...중략...

 

[Case 2] filebeat 빠른 재시작 시 사용하기 위한 설정

filebeat.inputs:
- type: log
...중략...
  ignore_older: 10m
  tail_files: true
...중략...

가볍게 설정에 대해서 알아보면,

- ignore_older 는 파일의 시간을 가지고 설정된 시간이 지난 파일은 무시 하게 됩니다.

- tail_files 는 파일의 처음 부터 읽을 건지 마지막 부터 읽을 건지 설정을 하게 됩니다.

 

:

[Elasticsearch] Date Format & Logback Timestamp Format

Elastic/Elasticsearch 2021. 10. 6. 12:18

Elasticsearch 에서 data field 를 이용해서 range 질의를 하기 위해서는 format 을 잘 맞춰 줘야 합니다.

Springboot 로 개발 한 WAS 에서 로그를 JSON 으로 찍으면서 timestamp 값에 대한 format 기 위한 설정에 대해서 기록 합니다.

 

참고문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
http://logback.qos.ch/manual/layouts.html

 

Logback Timestamp Format & JSON 설정)

https://jjeong.tistory.com/1570

  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
        <timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</timestampFormat>
        <timestampFormatTimezoneId>Asia/Seoul</timestampFormatTimezoneId>
        <appendLineSeparator>true</appendLineSeparator>
        <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
          <prettyPrint>true</prettyPrint>
        </jsonFormatter>
      </layout>
    </encoder>
  </appender>

 

Timestamp Formet Index)

{
  "mappings": {
    "properties": {
      "timestamp": {
        "type":   "date",
        "format": "strict_date_optional_time||epoch_millis",
        "ignore_malformed": true
      }
    }
  }
}

위 foramt 설정은 별도로 하지 않아도 기본 설정 됩니다.

 

Document Put)

{
    "timestamp" : "2021-10-06T11:33:46.855Z"
}

Range Query )

[Case 1]
{
    "query": {
        "range" : {
            "ts": {
                "gte": "2021-10-06T11:33:36.000Z",
                "lte": "2021-10-06T11:34:38.000Z"
            }
        }
    }
}

[Case 2]
{
    "query": {
        "range" : {
            "ts": {
                "gte": "2021-10-06 11:33:36.000",
                "lte": "2021-10-06 11:34:38.000",
                "format": "yyyy-MM-dd HH:mm:ss.SSS"
            }
        }
    }
}

결국 입력 값이 정확 하면 질의 시 format 을 지정해서 편하게 검색이 가능 합니다.

 

:

[Logback] JSON Layout Format 적용하기.

ITWeb/개발일반 2021. 10. 5. 18:52

Springboot 로 프로젝트 생성 후 로깅 하면서 로그 포멧을 JSON 으로 적용 하기 위한 내용을 기억 차원에서 작성 합니다.

 

[logback.xml]

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
        <timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</timestampFormat>
        <timestampFormatTimezoneId>Asia/Seoul</timestampFormatTimezoneId>
        <appendLineSeparator>true</appendLineSeparator>
        <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
          <prettyPrint>true</prettyPrint>
        </jsonFormatter>
      </layout>
    </encoder>
  </appender>

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>application/application.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>application/application-%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>

    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
        <timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</timestampFormat>
        <timestampFormatTimezoneId>Asia/Seoul</timestampFormatTimezoneId>
        <appendLineSeparator>true</appendLineSeparator>
        <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
          <prettyPrint>true</prettyPrint>
        </jsonFormatter>
      </layout>
    </encoder>
  </appender>

  <logger name="org.springframework" level="error" additivity="false" />
  <logger name="org.apache" level="error" additivity="false" />
  <logger name="com.zaxxer" level="error" additivity="false" />
  <logger name="io.netty" level="error" additivity="false" />
  <logger name="reactor" level="error" additivity="false" />
  <logger name="com.xxxxx" level="debug" additivity="false">
    <appender-ref ref="FILE" />
  </logger>

  <root level="debug">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
  </root>
</configuration>

 

[build.gradle]

compile "ch.qos.logback.contrib:logback-jackson:${props.getProperty('logback-jackson')}"
compile "ch.qos.logback.contrib:logback-json-classic:${props.getProperty('logback-json-classic')}"

- 여기서 사용 버전은 0.1.5 입니다.

 

사용한 timezone 은 ETC/UTC 가 아닌 Asia/Seoul 로 설정 했습니다.

: