1. 설치
[elastic@localhost ~]$ cd elasticsearch-8.1.1/
[elastic@localhost ~]$ ./bin/elasticsearch-plugin install analysis-nori
elasticsearch 재실행
2. 테스트
GET _analyze
{
"tokenizer": "standard",
"text": [
"전장연 이준석, 박원순 얘길 오세훈에게 따진다? 이명박 시장이 처음 약속"
]
}
GET _analyze
{
"tokenizer": "nori_tokenizer",
"text": [
"전장연 이준석, 박원순 얘길 오세훈에게 따진다? 이명박 시장이 처음 약속"
]
}
###################################################################
############################ nori analyzer ######################
###################################################################
############## 1. 구성
# nori analyzer는 다음과 같은 tokenizer와 token filters로 구성되어 있다
# nori_tokenizer
# nori_readingform 필터: 한자를 한글로
# lowercase 필터: 소문자화
# nori_part_of_speech 필터: stoptag를 사용하여 특정 태그 제외
GET _analyze
{
"tokenizer": "standard",
"text": [
"동해물과 백두산이 Mountain"
]
}
GET _analyze
{
"tokenizer": "nori_tokenizer",
"text": [
"동해물과 백두산이 Mountain"
]
}
GET _analyze
{
"explain": true,
"tokenizer": "nori_tokenizer",
"text": [
"동해물과 백두산이 Mountain"
]
}
DELETE nori_sample
PUT nori_sample
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "nori_tokenizer",
"filter": [
"my_posfilter",
"lowercase"
]
}
},
"filter": {
"my_posfilter": {
"type": "nori_part_of_speech",
"stoptags": [
"E",
"IC",
"J",
"MAG", "MAJ", "MM",
"SP", "SSC", "SSO", "SC", "SE",
"XPN", "XSA", "XSN", "XSV",
"UNA", "NA", "VSV"
]
}
}
}
}
}
}
GET nori_sample/_analyze
{
"analyzer": "my_analyzer",
"text": "동해물과 백두산이 Mountain"
}
# nori 품사태그: 첨부파일 참조
# 2. 주요 옵션
############# user_dictionary : 사용자 사전이 저장된 파일의 경로를 입력합니다.
# "user_dictionary": "userdict_ko.txt" 실제 저장위치는 ./config 아래 저장
# 사전 변경시시 POST index/_close(_open) 해야 반영됨
############# user_dictionary_rules : 사용자 정의 사전을 배열로 입력합니다.
############# decompound_mode : 합성어의 저장 방식을 결정합니다. 다음 3개의 값을 사용 가능합니다.
# none : 어근을 분리하지 않고 완성된 합성어만 저장합니다.
# discard (디폴트) : 합성어를 분리하여 각 어근만 저장합니다.
# mixed : 어근과 합성어를 모두 저장합니다.
################################## decompound_mode
PUT my_nori
{
"settings": {
"analysis": {
"tokenizer": {
"nori_none": {
"type": "nori_tokenizer",
"decompound_mode": "none"
},
"nori_discard": {
"type": "nori_tokenizer",
"decompound_mode": "discard"
},
"nori_mixed": {
"type": "nori_tokenizer",
"decompound_mode": "mixed"
}
}
}
}
}
GET my_nori/_analyze
{
"tokenizer": "nori_none",
"text": [ "백두산이" ]
}
DELETE nori_sample
################################## user_dictionary
PUT nori_sample
{
"settings": {
"index": {
"analysis": {
"tokenizer": {
"nori_user_dict": {
"type": "nori_tokenizer",
"decompound_mode": "none",
"user_dictionary": "userdict_ko.txt"
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "nori_user_dict"
}
}
}
}
}
}
POST nori_sample/_close
POST nori_sample/_open
GET nori_sample/_analyze
{
"analyzer": "my_analyzer",
"text": [ "동해물과 백두산이 마르고 닿도록 하느님이 보우하사 우리나라 만세" ]
}
################################## 동의어사전, 불용어사전
DELETE nori_sample
PUT nori_sample
{
"settings": {
"index": {
"analysis": {
"tokenizer": {
"nori_user_dict": {
"type": "nori_tokenizer",
"decompound_mode": "none",
"user_dictionary": "userdict_ko.txt"
}
},
"filter":{
"nori_posfilter":{
"type":"nori_part_of_speech",
"stoptags":[
"E","IC","J","MAG","MM","NA","NR","SC",
"SE","SF","SH","SL","SN","SP","SSC","SSO",
"SY","UNA","UNKNOWN","VA","VCN","VCP","VSV",
"VV","VX","XPN","XR","XSA","XSN","XSV"
]
},
"synonym_filter":{
"type":"synonym",
"synonyms_path":"synonym.txt"
},
"stop_filter":{
"type":"stop",
"stopwords_path":"stop.txt"
}
},
"analyzer": {
"my_analyzer": {
"tokenizer": "nori_user_dict",
"filter": ["nori_posfilter", "synonym_filter", "stop_filter", "lowercase"]
}
}
}
}
}
}
GET nori_sample/_analyze
{
"analyzer": "my_analyzer",
"text": [ "동해물과 백두산이 마르고 닿도록 하느님이 보우하사 우리나라 만세 노래바 씨발" ]
}
# synonym 필터의 경우는 쓰여진 모든 단어가 추가, 즉 노래바를 입력하면 노래빠 노래방 모두 추가
##################### 변경된 사전을 기존 인덱스에 반영하려면
# Elasticsearch에서는 문서가 업데이트 되었을때, document가 제거되고 다시 생성되면, 재인덱싱이 된다.
# update by query 를 이용하여 재인덱싱하면 된다.
POST nori_sample/_update_by_query
'Elasticsearch8' 카테고리의 다른 글
Ubuntu 22.04 부팅시 Elasticsearch 자동 실행 (0) | 2023.06.12 |
---|---|
[CentOS8, Ubuntu 22.04] Kibana 설치 , 설정, 접속 (0) | 2022.03.28 |
[Centos8, Ubuntu 22.04] Elasticsearch 설치 , 실행, 종료 (0) | 2022.03.25 |