# Dec 17th, 2020: \[KR\] Elastic Cloud 에서 한글 형태소 분석기 사용하기

**URL:** <https://discuss.elastic.co/t/dec-17th-2020-kr-elastic-cloud/258379>\
**Category:** Advent Calendar\
**Created:** [December 17, 2020, 8:00am UTC](https://discuss.elastic.co/t/dec-17th-2020-kr-elastic-cloud/258379 "2020-12-17T08:00:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimjmin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimjmin/32/15223_2.png) [@kimjmin](https://discuss.elastic.co/u/kimjmin)\
**Post date:** [December 17, 2020, 8:00am UTC](https://discuss.elastic.co/t/dec-17th-2020-kr-elastic-cloud/258379/1 "2020-12-17T08:00:00Z")

</div>

Elasticsearch 에서는 Elastic 에서 공식으로 제공하는 한글 형태소 분석기인 [nori](https://www.elastic.co/kr/blog/nori-the-official-elasticsearch-plugin-for-korean-language-analysis) 를 사용할 수 있습니다. 한글은 띄어쓰기가 없는 복합어가 대다수이기 때문에 의도하지 않은 대로 분석이 되는 경우가 많아 nori 를 사용하기 위해서는 목적에 맞는 사용자 사전을 등록해야 할 때가 많습니다.

nori\_tokenizer 에서는 사용자 사전을 텍스트 파일로 만들어 등록하거나 인덱스의 settings 정보에 직접 입력을 할 수도 있습니다.

`userdict_ko.txt` 파일에 사전을 등록하고 `user_dictionary` 옵션으로 사전 파일을 지정하는 예

```auto
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"
          }
        }
      }
    }
  }
}

```

REST API 를 이용해서 `user_dictionary_rules` 옵션에 사전을 직접 등록하는 예

```auto
PUT nori_sample
{
  "settings": {
    "index": {
      "analysis": {
        "tokenizer": {
          "nori_user_dict": {
            "type": "nori_tokenizer",
            "decompound_mode": "mixed",
            "user_dictionary_rules": ["c++", "C샤프", "세종", "세종시 세종 시"]
          }
        },
        "analyzer": {
          "my_analyzer": {
            "type": "custom",
            "tokenizer": "nori_user_dict"
          }
        }
      }
    }
  }
}

```

`user_dictionary_rules` 옵션의 경우 Elastic Cloud 에서도 문제 없이 사용이 가능하지만, 사용자 사전을 파일로 관리하고 싶은 경우 Elastic Cloud 에서는 어떻게 해야 할까요?

먼저 사전 파일은 zip 형식으로 압축해야 하는데, 사전 파일은 반드시 `dictionaries` 디렉토리 아래에 있어야 하고 `dictionaries` 를 포함하는 위치를 zip 파일의 루트 경로로 해야 합니다. 여기서는 사전 파일을 `nori-sample.txt` 로 했습니다.

```auto
$ tree .
.
└── dictionaries
    └── nori-sample.txt

```

그리고 Elastic Cloud 의 `Extensions` 메뉴에서 압축한 사전 파일을 등록합니다. 이 때 Type 은 `A bundle containing a dictionary or script` 로 지정해야 합니다. 아래 예제에서는 extension 이름을 `nori-dict` 라는 이름으로 저장했습니다.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/3/c3a698c1d1d3d1f7767886d988b29416e3044872.jpeg)

이제 Elasticsearch 클러스터 설정에 가서

 ![스크린샷 2020-12-11 오후 4.27.02](https://us1.discourse-cdn.com/elastic/original/3X/c/0/c05c0071aaab0eb473822054af18f259b4b4466e.png)

앞서 저장한 Extensions 를 선택하고 저장해서 클러스터를 재시작 해 줍니다.

 ![스크린샷 2020-12-11 오후 4.27.19](https://us1.discourse-cdn.com/elastic/original/3X/2/3/23f77e1dda424b3773121d9559189bf0e750f19b.jpeg)

이제 Elastic Cloud 의 클러스터에서 `nori-sample.txt` 파일을 지정해서 nori analyzer를 만들 수 있습니다.

```auto
PUT nori_test
{
  "settings": {
    "index": {
      "analysis": {
        "tokenizer": {
          "nori_user_dict": {
            "type": "nori_tokenizer",
            "decompound_mode": "mixed",
            "user_dictionary": "nori-sample.txt"
          }
        },
        "analyzer": {
          "my_nori": {
            "type": "custom",
            "tokenizer": "nori_user_dict"
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "message": {
        "type": "text",
        "fields": {
          "my_nori": {
            "type": "text",
            "analyzer": "my_nori"
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 14, 2021, 8:00am UTC](https://discuss.elastic.co/t/dec-17th-2020-kr-elastic-cloud/258379/2 "2021-01-14T08:00:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
