Stop analyzer
출처: 문서
본문
Stop 분석기
stop 분석기는 미리 정의된 불용어 목록을 제거합니다. 이 분석기는 lowercase 토크나이저와 stop 토큰 필터로 구성됩니다.
파라미터
stop 분석기는 다음 파라미터로 구성할 수 있습니다.
| 파라미터 | 필수/선택 | 데이터 타입 | 설명 |
|---|---|---|---|
stopwords |
선택 | 문자열 또는 문자열 배열 | 미리 정의된 불용어 목록(예: _english_)을 지정하는 문자열 또는 사용자 정의 불용어 목록을 지정하는 배열입니다. 기본값은 _english_입니다. |
stopwords_path |
선택 | 문자열 | 불용어 목록이 포함된 파일의 경로(절대 경로 또는 config 디렉터리 기준 상대 경로)입니다. |
예제
다음 명령을 사용하여 stop 분석기가 포함된 my_stop_index라는 인덱스를 생성하세요:
PUT /my_stop_index
{
"mappings": {
"properties": {
"my_field": {
"type": "text",
"analyzer": "stop"
}
}
}
}
{% include copy-curl.html %}
사용자 정의 분석기 구성
다음 명령을 사용하여 stop 분석기와 동등한 사용자 정의 분석기로 인덱스를 구성하세요:
PUT /my_custom_stop_analyzer_index
{
"settings": {
"analysis": {
"analyzer": {
"my_custom_stop_analyzer": {
"tokenizer": "lowercase",
"filter": [
"stop"
]
}
}
}
},
"mappings": {
"properties": {
"my_field": {
"type": "text",
"analyzer": "my_custom_stop_analyzer"
}
}
}
}
{% include copy-curl.html %}
생성된 토큰
다음 요청을 사용하여 분석기로 생성된 토큰을 확인하세요:
POST /my_custom_stop_analyzer_index/_analyze
{
"analyzer": "my_custom_stop_analyzer",
"text": "The large turtle is green and brown"
}
{% include copy-curl.html %}
응답에는 생성된 토큰이 포함됩니다:
{
"tokens": [
{
"token": "large",
"start_offset": 4,
"end_offset": 9,
"type": "word",
"position": 1
},
{
"token": "turtle",
"start_offset": 10,
"end_offset": 16,
"type": "word",
"position": 2
},
{
"token": "green",
"start_offset": 20,
"end_offset": 25,
"type": "word",
"position": 4
},
{
"token": "brown",
"start_offset": 30,
"end_offset": 35,
"type": "word",
"position": 6
}
]
}
불용어 지정
다음 예제 요청은 사용자 정의 불용어 목록을 지정합니다:
PUT /my_new_custom_stop_index
{
"settings": {
"analysis": {
"analyzer": {
"my_custom_stop_analyzer": {
"type": "stop",
"stopwords": ["is", "and", "was"]
}
}
}
},
"mappings": {
"properties": {
"description": {
"type": "text",
"analyzer": "my_custom_stop_analyzer"
}
}
}
}
{% include copy-curl.html %}
다음 예제 요청은 불용어가 포함된 파일의 경로를 지정합니다:
PUT /my_new_custom_stop_index
{
"settings": {
"analysis": {
"analyzer": {
"my_custom_stop_analyzer": {
"type": "stop",
"stopwords_path": "stopwords.txt"
}
}
}
},
"mappings": {
"properties": {
"description": {
"type": "text",
"analyzer": "my_custom_stop_analyzer"
}
}
}
}
{% include copy-curl.html %}
이 예제에서 파일은 config 디렉터리에 있습니다. 파일의 전체 경로를 지정할 수도 있습니다.