Character group tokenizer
출처: 문서
본문
Character group 토크나이저
char_group 토크나이저는 특정 문자를 구분자로 사용해서 텍스트를 토큰으로 분리해요. 단순한 방식의 토큰화가 필요한 상황에 적합하며, 복잡한 설정을 추가하지 않으면서 패턴 기반 토크나이저보다 간단한 대안을 제공해요.
사용 예시
다음 예시 요청은 my_index라는 이름의 새 인덱스를 생성하고 char_group 토크나이저로 애널라이저를 설정해요. 이 토크나이저는 공백, -, : 문자를 기준으로 텍스트를 분리해요:
PUT /my_index
{
"settings": {
"analysis": {
"tokenizer": {
"my_char_group_tokenizer": {
"type": "char_group",
"tokenize_on_chars": [
"whitespace",
"-",
":"
]
}
},
"analyzer": {
"my_char_group_analyzer": {
"type": "custom",
"tokenizer": "my_char_group_tokenizer"
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "my_char_group_analyzer"
}
}
}
}
{% include copy-curl.html %}
생성된 토큰
애널라이저로 생성된 토큰을 확인하려면 다음 요청을 사용해요:
POST /my_index/_analyze
{
"analyzer": "my_char_group_analyzer",
"text": "Fast-driving cars: they drive fast!"
}
{% include copy-curl.html %}
응답에는 생성된 토큰이 담겨 있어요:
{
"tokens": [
{
"token": "Fast",
"start_offset": 0,
"end_offset": 4,
"type": "word",
"position": 0
},
{
"token": "driving",
"start_offset": 5,
"end_offset": 12,
"type": "word",
"position": 1
},
{
"token": "cars",
"start_offset": 13,
"end_offset": 17,
"type": "word",
"position": 2
},
{
"token": "they",
"start_offset": 19,
"end_offset": 23,
"type": "word",
"position": 3
},
{
"token": "drive",
"start_offset": 24,
"end_offset": 29,
"type": "word",
"position": 4
},
{
"token": "fast!",
"start_offset": 30,
"end_offset": 35,
"type": "word",
"position": 5
}
]
}
파라미터
char_group 토크나이저는 다음 파라미터로 설정할 수 있어요.
| 파라미터 | 필수/선택 | 데이터 타입 | 설명 |
|---|---|---|---|
tokenize_on_chars |
필수 | Array | 텍스트를 토큰화할 기준이 되는 문자 집합을 지정해요. 개별 문자(예: - 또는 @), 이스케이프 문자(예: \n)를 지정할 수 있고, whitespace, letter, digit, punctuation, symbol 같은 문자 클래스도 지정할 수 있어요. |
max_token_length |
선택 | Integer | 생성되는 토큰의 최대 길이를 설정해요. 이 길이를 초과하면 max_token_length에 설정된 길이를 기준으로 토큰이 여러 개로 나뉘어요. 기본값은 255예요. |