Table of Contents
ElasticSearch 추가설정
아래에는 형태소분석기 설정, JDBC 연동 을 기초로 최종적으로 정리하는 글입니다.
사전 추가
사용자 사전
복합명사는 +
를 이용해 등록합니다. +
는 \+
로 등록합니다.
sudo vi /etc/elasticsearch/user_dict.csv
텐바이텐,-1000
엠디,-100
아이폰+케이스,-1000
c\+\+
유의어 사전
sudo vi /etc/elasticsearch/synonyms.txt
블랙,검정,black
불용어
불용어에는 욕설 등 제거해야 하는 단어 뿐만 아니라, 키워드로서의 가치가 없는 단어(대부분의 문서에 등장하는 흔한 단어)도 등록하면 검색성능이 향상됩니다.
sudo vi /etc/elasticsearch/stopwords.txt
욕설들
개자식
인덱스 설정
curl -XDELETE http://localhost:9200/items?pretty
curl -XPUT http://localhost:9200/items?pretty -H 'Content-Type: application/json' -d '{
"settings" : {
"number_of_shards": "5",
"number_of_replicas": "1",
"index":{
"analysis":{
"analyzer":{
"korean":{
"type":"custom",
"tokenizer":"seunjeon_default_tokenizer",
"filter" : ["lowercase", "synonym", "stopword"]
}
},
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms_path" : "synonyms.txt"
},
"stopword" : {
"type" : "stop",
"stopwords_path" : "stopwords.txt"
}
},
"tokenizer": {
"seunjeon_default_tokenizer": {
"index_eojeol": "true",
"user_dict_path": "user_dict.csv",
"index_poses": [
"UNK", "EP", "I", "J", "M",
"N", "SL", "SH", "SN", "VCP",
"XP", "XS", "XR"
],
"decompound": "true",
"type": "seunjeon_tokenizer"
}
}
}
}
},
"mappings" : {
"_doc" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"itemid" : {
"type" : "integer"
},
"itemname" : {
"type" : "text",
"analyzer": "korean"
},
"category" : {
"type" : "text",
"analyzer": "korean"
},
"price" : {
"type": "scaled_float",
"scaling_factor": 10000
},
"lastupdate" : {
"type" : "date"
},
"regdate" : {
"type" : "date"
}
}
}
}
}'
curl -XGET http://localhost:9200/items/_search?pretty -H 'Content-Type: application/json' -d '{
"query": {
"match": {
"itemname": "black아이폰케이스"
}
}
}'
curl -XGET http://localhost:9200/items/_search?pretty -H 'Content-Type: application/json' -d '{
"query": {
"match": {
"itemname": "화이트 아이폰 케이블"
}
},
"explain": true
}'
curl -XGET http://localhost:9200/items/_analyze?pretty -H 'Content-Type: application/json' -d '{
"analyzer":"korean",
"text":"텐바이텐 엠디가 추천합니다."
}'