결국 무엇이든 해내는 사람

ElasticSearch - standard, letter, whitespace 토크나이저 [ 예제, 설명 ] 본문

두서없는 공부 노트/ElasticSearch

ElasticSearch - standard, letter, whitespace 토크나이저 [ 예제, 설명 ]

kkm8257 2021. 12. 14. 15:40
반응형
-- standard 토크나이저
GET _analyze
{
  "tokenizer": "standard",
  "text": "THE quick.brown_FOx jumped! @ 3.5 meters."
}


-- 결과
-- 공백으로 텀을 구분하면서 "@"와 같은 특수문자 제거
-- 단어 끝에 있는 느낌표나 "."는 제거 되지만, 중간에 있는 마침표나 밑줄 등은 제거되거나 분리되지 않는다.
{
  "tokens" : [
    {
      "token" : "THE",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "quick.brown_FOx",
      "start_offset" : 4,
      "end_offset" : 19,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "jumped",
      "start_offset" : 20,
      "end_offset" : 26,
      "type" : "<ALPHANUM>",
      "position" : 2
    },
    {
      "token" : "3.5",
      "start_offset" : 30,
      "end_offset" : 33,
      "type" : "<NUM>",
      "position" : 3
    },
    {
      "token" : "meters",
      "start_offset" : 34,
      "end_offset" : 40,
      "type" : "<ALPHANUM>",
      "position" : 4
    }
  ]
}





-- letter 토크나이저
GET _analyze
{
  "tokenizer": "letter",
  "text": "THE quick.brown_FOx jumped! @ 3.5 meters."
}


-- 결과
-- 알파벳을 제외한 모든 공백, 숫자, 기호들을 기준으로 텀을 분리한다.
-- 특수문자, 숫자, 기호들은 제거
{
  "tokens" : [
    {
      "token" : "THE",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "quick",
      "start_offset" : 4,
      "end_offset" : 9,
      "type" : "word",
      "position" : 1
    },
    {
      "token" : "brown",
      "start_offset" : 10,
      "end_offset" : 15,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "FOx",
      "start_offset" : 16,
      "end_offset" : 19,
      "type" : "word",
      "position" : 3
    },
    {
      "token" : "jumped",
      "start_offset" : 20,
      "end_offset" : 26,
      "type" : "word",
      "position" : 4
    },
    {
      "token" : "meters",
      "start_offset" : 34,
      "end_offset" : 40,
      "type" : "word",
      "position" : 5
    }
  ]
}




-- whitespace 토크나이저
GET _analyze
{
  "tokenizer": "whitespace",
  "text": "THE quick.brown_FOx jumped! @ 3.5 meters."
}


-- 결과
-- 스페이스, 탭, 줄바꿈, 공백 만을 기준으로 텀을 분리한다
-- 특수문자나 마지막에 있는 마침표도 사라지지 않고 그대로 남아있다
{
  "tokens" : [
    {
      "token" : "THE",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "quick.brown_FOx",
      "start_offset" : 4,
      "end_offset" : 19,
      "type" : "word",
      "position" : 1
    },
    {
      "token" : "jumped!",
      "start_offset" : 20,
      "end_offset" : 27,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "@",
      "start_offset" : 28,
      "end_offset" : 29,
      "type" : "word",
      "position" : 3
    },
    {
      "token" : "3.5",
      "start_offset" : 30,
      "end_offset" : 33,
      "type" : "word",
      "position" : 4
    },
    {
      "token" : "meters.",
      "start_offset" : 34,
      "end_offset" : 41,
      "type" : "word",
      "position" : 5
    }
  ]
}


-- letter 토크나이저의 경우 검색 범위가 넓어져서 원하는 결과가 많이 나올 수 있음
-- whitespace 토크나이저는 특수문자를 거르지 않기 때문에 정확하게 검색하지 않으면 검색결과가 안 나올 수 있음
-- 주로 standard 토크나이저를 많이 사용






반응형
Comments