Korean (nori) Analysis Plugin

By | 2022년 8월 19일
Table of Contents

Korean (nori) Analysis Plugin

한글을 Tokenizing 하기 위해 nori Analyser 를 사용할 수 있다.

설치

# install
sudo bin/elasticsearch-plugin install analysis-nori

# remove
sudo bin/elasticsearch-plugin remove analysis-nori

nori_tokenizer

설정

  • decompound_mode : 복합어 처리방식

    • none : 분리안함

    • discard : 분리어만

    • mixed : 복합어 + 분리어 모두 포함

  • user_dictionary : 사용자 사전

샘플

PUT nori_sample

{
  "settings": {
    "index": {
      "analysis": {
        "tokenizer": {
          "nori_user_dict": {
            "type": "nori_tokenizer",
            "decompound_mode": "mixed",
            "discard_punctuation": "false",
            "user_dictionary": "userdict_ko.txt"
          }
        },
        "analyzer": {
          "my_analyzer": {
            "type": "custom",
            "tokenizer": "nori_user_dict"
          }
        }
      }
    }
  }
}

GET nori_sample/_analyze

{
  "analyzer": "my_analyzer",
  "text": "1800사무용책상",
  "explain": true
}

Reload search analyzers API

사전파일이 수정되었을 때, search analyzer 를 reload 해야 합니다.

POST /my-index-000001/_reload_search_analyzers
POST /my-index-000001/_cache/clear?request=true

사전파일 배포방안

Dockerizing

도커로 Elasticsearch 를 관리한다면,
Dockerizing 할 때 사전파일에 포함하는 방법이 있습니다.

공유 폴더에 파일 업로드

Custom plugin 만들기

Custom plugin 에서 특정 URL 에서 파일을 다운받고,
사전파일을 엎어치는 방식입니다.

/home/elasticsearch/.java.policy 파일을 생성하고,
아래와 같이 파일 수정권한을 부여해야 합니다.

grant {
    permission java.io.FilePermission "/tmp/patient_similarity/codes.txt", "read,write";
};

답글 남기기