본문 바로가기
WIKI 기술 지식 베이스

CJK analyzer

원문 보기 위키 갱신

출처: 문서

본문

CJK 분석기

내장된 cjk 분석기는 중국어, 일본어, 한국어(CJK) 텍스트를 위해 설계되었어요. 이 분석기는 바이그램 토큰화를 사용하여 CJK 텍스트를 겹치는 두 글자 시퀀스로 분해하는데, 이는 단어를 구분하기 위해 공백을 사용하지 않는 언어에 효과적이에요.

ICU 분석 플러그인의 icu_analyzer가 cjk 분석기보다 CJK 텍스트에 더 잘 작동할 수도 있어요. 자신의 텍스트와 쿼리로 실험해 보세요. {: .note}

cjk 분석기는 다음 명령을 사용하여 텍스트 필드에 적용할 수 있어요:

PUT /cjk-index
{
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "cjk"
      }
    }
  }
}

{% include copy-curl.html %}

어간 제외

다음 명령을 사용하여 이 언어 분석기에 stem_exclusion을 사용할 수 있어요:

PUT index_with_stem_exclusion_cjk_analyzer
{
  "settings": {
    "analysis": {
      "analyzer": {
        "stem_exclusion_cjk_analyzer": {
          "type": "cjk",
          "stem_exclusion": ["example", "words"]
        }
      }
    }
  }
}

{% include copy-curl.html %}

CJK 분석기 내부 구조

cjk 분석기는 다음 구성 요소를 사용하여 구축되었어요:

  • 토크나이저: standard

  • 토큰 필터:

    • cjk_width
    • lowercase
    • cjk_bigram
    • stop (영어와 유사)

사용자 정의 CJK 분석기

다음 명령을 사용하여 사용자 정의 CJK 분석기를 만들 수 있어요:

PUT /cjk-index
{
  "settings": {
    "analysis": {
      "filter": {
        "english_stop": {
          "type":       "stop",
          "stopwords":  [ 
            "a", "and", "are", "as", "at", "be", "but", "by", "for",
            "if", "in", "into", "is", "it", "no", "not", "of", "on",
            "or", "s", "such", "t", "that", "the", "their", "then",
            "there", "these", "they", "this", "to", "was", "will",
            "with", "www"
          ]
        }
      },
      "analyzer": {
        "cjk_custom_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "cjk_width",
            "lowercase",
            "cjk_bigram",
            "english_stop"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "cjk_custom_analyzer"
      }
    }
  }
}

{% include copy-curl.html %}

생성된 토큰

다음 요청을 사용하여 분석기로 생성된 토큰을 확인할 수 있어요:

POST /cjk-index/_analyze
{
  "field": "content",
  "text": "学生们在中国、日本和韩国的大学学习。123456"
}

{% include copy-curl.html %}

응답에는 생성된 토큰이 포함되어 있어요:

{
  "tokens": [
    {"token": "学生","start_offset": 0,"end_offset": 2,"type": "<DOUBLE>","position": 0},
    {"token": "生们","start_offset": 1,"end_offset": 3,"type": "<DOUBLE>","position": 1},
    {"token": "们在","start_offset": 2,"end_offset": 4,"type": "<DOUBLE>","position": 2},
    {"token": "在中","start_offset": 3,"end_offset": 5,"type": "<DOUBLE>","position": 3},
    {"token": "中国","start_offset": 4,"end_offset": 6,"type": "<DOUBLE>","position": 4},
    {"token": "日本","start_offset": 7,"end_offset": 9,"type": "<DOUBLE>","position": 5},
    {"token": "本和","start_offset": 8,"end_offset": 10,"type": "<DOUBLE>","position": 6},
    {"token": "和韩","start_offset": 9,"end_offset": 11,"type": "<DOUBLE>","position": 7},
    {"token": "韩国","start_offset": 10,"end_offset": 12,"type": "<DOUBLE>","position": 8},
    {"token": "国的","start_offset": 11,"end_offset": 13,"type": "<DOUBLE>","position": 9},
    {"token": "的大","start_offset": 12,"end_offset": 14,"type": "<DOUBLE>","position": 10},
    {"token": "大学","start_offset": 13,"end_offset": 15,"type": "<DOUBLE>","position": 11},
    {"token": "学学","start_offset": 14,"end_offset": 16,"type": "<DOUBLE>","position": 12},
    {"token": "学习","start_offset": 15,"end_offset": 17,"type": "<DOUBLE>","position": 13},
    {"token": "123456","start_offset": 18,"end_offset": 24,"type": "<NUM>","position": 14}
  ]
}

관련 문서

더 알아보기 (Learn more)