Nori 설치는 공식 플러그인이다보니 너무 쉽게 변했죠.

이번엔 이걸 이용해서 인덱스 설치를ㄹㄹㄹ...

 

노리에 대한 정보는...

https://www.elastic.co/guide/en/elasticsearch/plugins/7.0/analysis-nori-analyzer.html

 

nori analyzer | Elasticsearch Plugins and Integrations [7.0] | Elastic

 

www.elastic.co

 

위 링크 가시면  필터와 토크나이저에 대한 링크가 있으며, 해당 링크에는 예제와 설명들이 있습니다.

 

저는 저걸 섞어서 인덱스 하나만 만들어 보도록 할게요. 

 

작업은 Kibana > Dev Tools > Console 에서 진행하였습니다.

curl로 작업시 아래 부분이 필요하겠지용?

curl -H 'Content-Type: application/json' -X PUT http://127.0.0.1:9200/...

 

예제에 들어가기에 앞서 간략한 설명.

 

decompound_mode : 단어를 어떻게 분리 하는지...

 - none, discard, mixed 세가지가 있고요.

 - none : 분리안함.

 - discard : 기본값이고요. 단어를 사전에 있는 단어 기준으로 분리하는거에요.

 - mixed : 위 두가지 혼합. 원래 단어(조사?맞나? 제외)와 사전 기준 쪼개진 단어를 분리하는 두 결과 모두를 출력.

 

nori_readingform : 한문을 한글로 변환해주는 친구

- REQUEST
GET /index01/_analyze
{
  "analyzer": "korean",
  "text" : "金"
}

- RESULTS
{
  "tokens" : [
    {
      "token" : "김",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "word",
      "position" : 0
    }
  ]
}

lowercase : 영문자를 소문자로 해주는 친구

 

nori_part_of_speech : 품사 태그 배열, 즉 stoptags에 포함된 걸 만나면 제거해서 결과를 주는 그런 친구인데...

저 안에 배열이 정확히 뭘 의미하는지 궁금하다면 ...

http://lucene.apache.org/core/8_0_0/analyzers-nori/org/apache/lucene/analysis/ko/POS.Tag.html

 

POS.Tag (Lucene 8.0.0 API)

values() Returns an array containing the constants of this enum type, in the order they are declared.

lucene.apache.org

위 페이지 한글로 번역하기 돌리면 아주 잘 나와요.

저는 공식 문서에 있는 예제 그냥 갖다 붙인...ㅎㅎ

그리고 NR에 대한 예제가 있던데, 이건 숫자로 명사를 꾸미는 경우 숫자를 표현한 한글을 제거해주더라고요!

 


- REQUEST
PUT /index01
{
  "settings": {
    "number_of_shards" : 2,
    "number_of_replicas" :0,
    "index": {
      "analysis": {
        "tokenizer": {
          "nori_tokenizer_mixed": {
            "type": "nori_tokenizer",
            "decompound_mode": "mixed"
          }
        },
        "analyzer": {
          "korean": {
            "type": "custom",
            "tokenizer": "nori_tokenizer_mixed",
            "filter": ["nori_readingform", "lowercase", "nori_part_of_speech_basic"]
          }
        },
        "filter" : {
          "nori_part_of_speech_basic": {
            "type" : "nori_part_of_speech",
            "stoptags" : [
              "E",
              "IC",
              "J",
              "MAG", "MAJ", "MM",
              "SP", "SSC", "SSO", "SC", "SE",
              "XPN", "XSA", "XSN", "XSV",
              "UNA", "NA", "VSV"
            ]
          }
        }
      }
    }
  }
}

- RESULTS
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "index01"
}

 

생성된 인덱스를 확인~

- REQUEST
GET /index01

- RESULTS
{
  "index01" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "number_of_shards" : "2",
        "provided_name" : "index01",
        "creation_date" : "1556261305395",
        "analysis" : {
          "filter" : {
            "nori_part_of_speech_basic" : {
              "type" : "nori_part_of_speech",
              "stoptags" : [
                "E",
                "IC",
                "J",
                "MAG",
                "MAJ",
                "MM",
                "SP",
                "SSC",
                "SSO",
                "SC",
                "SE",
                "XPN",
                "XSA",
                "XSN",
                "XSV",
                "UNA",
                "NA",
                "VSV"
              ]
            }
          },
          "analyzer" : {
            "korean" : {
              "filter" : [
                "nori_readingform",
                "lowercase",
                "nori_part_of_speech_basic"
              ],
              "type" : "custom",
              "tokenizer" : "nori_tokenizer_mixed"
            }
          },
          "tokenizer" : {
            "nori_tokenizer_mixed" : {
              "type" : "nori_tokenizer",
              "decompound_mode" : "mixed"
            }
          }
        },
        "number_of_replicas" : "0",
        "uuid" : "xdcxjktjSSeoVUtFniPkSg",
        "version" : {
          "created" : "7000099"
        }
      }
    }
  }
}

 

그리고 간단한 문장 분석~

- REQUEST
GET /index01/_analyze
{
  "analyzer": "korean",
  "text" : "아버지가 방에 들어오신다"
}

- RESULTS
{
  "tokens" : [
    {
      "token" : "아버지",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "방",
      "start_offset" : 5,
      "end_offset" : 6,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "들어오",
      "start_offset" : 8,
      "end_offset" : 11,
      "type" : "word",
      "position" : 4
    }
  ]
}

 

그리고 index에서 shards를 2로 했는데요.

샤드에 관한건 

https://brownbears.tistory.com/4

 

노드 생성, 동작 원리 및 shard란?

1) 노드의 생성 및 동작 원리 사용자가 하나의 머신에서 Elasicsearch를 시작하게 되면, 하나의 Elasticsearch 노드가 생성되며, 이 노드는 동일한 네트워크 상에서 같은 클러스터명을 같는 클러스터가 존재하는..

brownbears.tistory.com

위에 링크 보시면 샤드에 대해 설명을 잘 해주셨더라고요. 

 

저는 어차피 단일 노드라서 ㅎㅎ 

샤드와 성능의 상관 관계는 많은 글들이 있지만, 

샤드는 많아질수록 빨라지다 느려지고, 하더라고요? 적정선을 유지하는게 좋다고 하는데..

샤드 수는 코어에 관련된 공식도 있던데...

위 글 보고 노드1개가 별 다른 설정없으면 샤드5개 라길래 1개보단 2개가 좋겠지 하고 2로 했어요.

 

그럼 저는 이만 총총총...

+ Recent posts