'format'에 해당되는 글 6건

  1. 2021.10.06 [Elasticsearch] Date Format & Logback Timestamp Format
  2. 2021.10.05 [Logback] JSON Layout Format 적용하기.
  3. 2016.07.22 [Elasticsearch] Transport Bulk to Rest Bulk data format 변환
  4. 2016.02.26 [Elasticsearch] Formatting Synonyms 알아보기
  5. 2015.11.30 [Elasticsearch - The Definitive Guide] bulk-format
  6. 2015.07.29 [Kibana4.x] Value format 설정하기

[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 로 설정 했습니다.

:

[Elasticsearch] Transport Bulk to Rest Bulk data format 변환

Elastic/Elasticsearch 2016. 7. 22. 10:02

java 로 bulk indexing 코드를 구현할 경우 색인 데이터 format을 그대로 rest bulk indexing 에서 사용을 할 수가 없습니다.

그래서 변환 하는 스크립트를 간단하게 작성해 봤습니다.


Reference)

https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-bulk.html


Java Bulk Indexing Format)

{ "field1" : "value1" }


Rest Bulk Indexing Format)

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }

{ "field1" : "value1" }


보시면 아시겠지만 index/type/id 에 대한 meta 정보가 있느냐 없느냐의 차이 입니다.

당연하겠지만 java api 에서는 meta 정보를 set 하도록 되어 있습니다. 하지만 rest api 에서는 set 하는 과정이 없기 때문에 당연히 정보를 위와 같이 넣어 줘야 합니다.


변환 스크립트)

#!/bin/bash


while read line

do

  header="{ \"index\" : { \"_index\" : \"INDEX_NAME\", \"_type\" : \"TYPE_NAME\" } }"

  echo -e $header >> query_result.txt

  echo -e $line >> query_result.txt

done < $1


실행)

$ ./convertJavaToRestFormat.sh query_result.json


Rest Bulk Action)

$ curl -XPOST 'http://localhost:9200/INDEX_NAME/TYPE_NAME/_bulk' --data-binary "@query_result.txt"


:

[Elasticsearch] Formatting Synonyms 알아보기

Elastic/Elasticsearch 2016. 2. 26. 14:48
synonym 구성을 어떻게 하는지 궁금해 하시는 분들이 있을 것 같아 정리해 봅니다.

내용은 elastic.co 의 "The Definitive Guide"에서 가져왔습니다.


[원문 링크]


[원문 Snippet]

In their simplest form, synonyms are listed as comma-separated values:

"jump,leap,hop"

If any of these terms is encountered, it is replaced by all of the listed synonyms. For instance:

Original terms:   Replaced by:
────────────────────────────────
jump             (jump,leap,hop)
leap             (jump,leap,hop)
hop              (jump,leap,hop)

Alternatively, with the => syntax, it is possible to specify a list of terms to match (on the left side),
and a list of one or more replacements (on the right side):

"u s a,united states,united states of america => usa"
"g b,gb,great britain => britain,england,scotland,wales"
Original terms:   Replaced by:
────────────────────────────────
u s a            (usa)
united states    (usa)
great britain    (britain,england,scotland,wales)

If multiple rules for the same synonyms are specified, they are merged together.
The order of rules is not respected. Instead, the longest matching rule wins.
Take the following rules as an example:

"united states            => usa",
"united states of america => usa"

If these rules conflicted, Elasticsearch would turn United States of America into the terms (usa),(of),
(america)
. Instead, the longest sequence wins, and we end up with just the term (usa).


두 가지 방법으로 설정 하는 예제가 나와 있습니다.


Case 1) "jump,leap,hop" 과 같이 double quotation 으로 묶는 방법

색인 시 jump 라는 term 이 발생 하게 되면 leap, hop 두 개의 term 이 추가 되어서 색인이 되게 됩니다.

그렇기 때문에 색인 크기가 증가 되는 이슈가 있을 수 있습니다.


Case 2) => 기호를 사용한 양자택일 방법

이 방법은 왼쪽에 있는 term을 오른쪽에 있는 term으로 replacement 하게 됩니다.



:

[Elasticsearch - The Definitive Guide] bulk-format

Elastic/TheDefinitiveGuide 2015. 11. 30. 11:43

Elasticsearch에서 bulk request 시 사용하는 format 에 대한 이야기 입니다.

이 이야기를 기록하는 이유는 elasticsearch 내부에서 동작하는 원리를 쉽게 이해 할 수 있기 때문 입니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/distrib-multi-doc.html#bulk-format


[Why the funny format?]

  • Parse the JSON into an array (including the document data, which can be very large)
  • Look at each request to determine which shard it should go to
  • Create an array of requests for each shard
  • Serialize these arrays into the internal transport format
  • Send the requests to each shard


정리하자면,

bulk request 를 받아서 다시 풀고 적절한 node의 shard 로 forward 되도록 생성한 후 send or request 한다 입니다.

:

[Kibana4.x] Value format 설정하기

Elastic/Kibana 2015. 7. 29. 17:46

kibana를 이용하다 보면 화면에 보여지는 값에 대한 format 을 고치고 싶은 욕구가 생깁니다.

이걸 어디서 고쳐줘야 하나 싶은데 역시 매뉴 몇번 눌러 보면 찾을 수 있습니다.

귀찮아 하시는 분들을 위해 공유해 봅니다.


[참고문서]

https://www.elastic.co/blog/kibana-4-1-field-formatters


[매뉴 tree]

## Global 설정

GNB -> Settings -> Advanced


## 특정 인덱스의 field format을 바꾸고 싶을 경우

GNB -> Settings -> Indices -> Select Index Patterns -> controls 컬럼에서 수정하고자 하는 field 클릭


[Advanced 화면]



: