Mapping character filter
출처: 문서
본문
매핑 문자 필터
mapping 문자 필터는 문자 대체를 위한 키-값 쌍의 맵을 받아들입니다. 필터가 키와 일치하는 문자열을 만나면 해당 값으로 대체합니다. 대체 값은 빈 문자열일 수 있습니다.
이 필터는 탐욕적 매칭을 적용합니다. 즉, 가장 긴 일치 패턴이 매칭됩니다.
mapping 문자 필터는 토큰화 전에 특정 텍스트 대체가 필요한 시나리오에서 유용합니다.
예제
다음 요청은 로마 숫자(예: I, II, III)를 해당 아라비아 숫자(1, 2, 3)로 변환하는 mapping 문자 필터를 구성합니다:
GET /_analyze
{
"tokenizer": "keyword",
"char_filter": [
{
"type": "mapping",
"mappings": [
"I => 1",
"II => 2",
"III => 3",
"IV => 4",
"V => 5"
]
}
],
"text": "I have III apples and IV oranges"
}
{% include copy-curl.html %}
응답에는 로마 숫자가 아라비아 숫자로 대체된 토큰이 포함됩니다:
{
"tokens": [
{
"token": "1 have 3 apples and 4 oranges",
"start_offset": 0,
"end_offset": 32,
"type": "word",
"position": 0
}
]
}
매개변수
다음 매개변수 중 하나를 사용하여 키-값 맵을 구성할 수 있습니다.
| 매개변수 | 필수/선택 | 데이터 유형 | 설명 |
|---|---|---|---|
mappings |
선택 | Array | key => value 형식의 키-값 쌍 배열입니다. 입력 텍스트에서 발견된 각 키는 해당 값으로 대체됩니다. |
mappings_path |
선택 | String | 키-값 매핑이 포함된 UTF-8 인코딩 파일의 경로입니다. 각 매핑은 key => value 형식으로 새 줄에 나타나야 합니다. 경로는 절대 경로이거나 OpenSearch 구성 디렉터리에 대한 상대 경로일 수 있습니다. |
사용자 정의 매핑 문자 필터 사용
자체 매핑 세트를 정의하여 사용자 정의 매핑 문자 필터를 만들 수 있습니다. 다음 요청은 텍스트에서 일반적인 약어를 대체하는 사용자 정의 문자 필터를 생성합니다:
PUT /test-index
{
"settings": {
"analysis": {
"analyzer": {
"custom_abbr_analyzer": {
"tokenizer": "standard",
"char_filter": [
"custom_abbr_filter"
]
}
},
"char_filter": {
"custom_abbr_filter": {
"type": "mapping",
"mappings": [
"BTW => By the way",
"IDK => I don't know",
"FYI => For your information"
]
}
}
}
}
}
{% include copy-curl.html %}
다음 요청을 사용하여 분석기로 생성된 토큰을 확인하세요:
GET /text-index/_analyze
{
"tokenizer": "keyword",
"char_filter": [ "custom_abbr_filter" ],
"text": "FYI, updates to the workout schedule are posted. IDK when it takes effect, but we have some details. BTW, the finalized schedule will be released Monday."
}
{% include copy-curl.html %}
응답은 약어가 대체되었음을 보여줍니다:
{
"tokens": [
{
"token": "For your information, updates to the workout schedule are posted. I don't know when it takes effect, but we have some details. By the way, the finalized schedule will be released Monday.",
"start_offset": 0,
"end_offset": 153,
"type": "word",
"position": 0
}
]
}