Elasticsearch 검색시에 한글 형태소를 사용하지 않으면 term을 단순하게 공백을 이용해서 쪼갠다. 하지만 한글말에는 조사도 구분해야하고 품사도 구분해서 사용해야 정확한 검색을 지원할 수 있다.
한글 형태소 플러그인은 크게 arirang, seunjeon, open korea text가 존재한다. 3개의 성능 비교와 자세한 설명은 엘라스틱 서치 블로그에서 참고하면 된다.
https://www.elastic.co/kr/blog/using-korean-analyzers
open korea text 설치
3가지 플러그인중에 open korea text를 사용해서 기능을 테스트해보자.
우선 docker를 사용중이므로 elasticsearch 내부 bash shell로 접속한 후 elasticsearch-plugin 명령어를 사용하여 설치해보자. 설치 파일은 github 페이지를 참고하면 된다. https://github.com/open-korean-text/elasticsearch-analysis-openkoreantext 
1 2 3 4 5  | #bash shell 접속 docker exec -it elastic /bin/bash #설치 bin/elasticsearch-plugin install https://github.com/open-korean-text/elasticsearch-analysis-openkoreantext/releases/download/6.1.1/elasticsearch-analysis-openkoreantext-6.1.1.2-plugin.zip  | cs | 
설치한 후 docker를 재시작 한다. 엘라스틱서치가 실행되면서 로그를 살펴보면 open korea text 모듈이 load 되는 것을 확인할 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  | [2018-09-13T13:41:28,292][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [aggs-matrix-stats] [2018-09-13T13:41:28,292][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [analysis-common] [2018-09-13T13:41:28,292][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [ingest-common] [2018-09-13T13:41:28,292][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [lang-expression] [2018-09-13T13:41:28,292][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [lang-mustache] [2018-09-13T13:41:28,292][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [lang-painless] [2018-09-13T13:41:28,293][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [mapper-extras] [2018-09-13T13:41:28,293][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [parent-join] [2018-09-13T13:41:28,293][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [percolator] [2018-09-13T13:41:28,293][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [reindex] [2018-09-13T13:41:28,293][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [repository-url] [2018-09-13T13:41:28,293][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [transport-netty4] [2018-09-13T13:41:28,293][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded module [tribe] [2018-09-13T13:41:28,294][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded plugin [analysis-seunjeon] [2018-09-13T13:41:28,294][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded plugin [elasticsearch-analysis-openkoreantext] [2018-09-13T13:41:28,294][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded plugin [ingest-geoip] [2018-09-13T13:41:28,294][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded plugin [ingest-user-agent] [2018-09-13T13:41:28,294][INFO ][o.e.p.PluginsService     ] [c-CqQL8] loaded plugin [x-pack]  | cs | 
인덱스 생성
간단하게 title만 가지고 있는 인덱스를 생성해보자. 생성할 때 analyzer를 설치한 open korea text를 지정해준다.
1 2 3 4 5 6 7 8 9 10 11 12 13  | PUT cgv      // 인덱스 {   "mappings" : {     "movie" : {   // 타입       "properties": {         "title" : {            "type" : "text",           "analyzer": "openkoreantext-analyzer"  // 형태소         }       }     }   } }  | cs | 
데이터 삽입
1 2 3 4 5 6 7 8 9  | POST cgv/movie/ {  "title" : "여전히 돈 많은 백수가 되고싶다展" } POST cgv/movie/ {  "title" : "뮤지컬 〈점프 (JUMP)〉- 서울전용극장(명보아트홀3F)" }  | cs | 
조회
비슷한 문자열을 가진 검색어를 통해서 검색을 해보자.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73  | #검색1 GET cgv/movie/_search {   "query": {     "match": {       "title": "뮤지컬 점프(JUMP)"     }   } } #결과1 {   "took": 23,   "timed_out": false,   "_shards": {     "total": 5,     "successful": 5,     "skipped": 0,     "failed": 0   },   "hits": {     "total": 1,     "max_score": 0.8630463,     "hits": [       {         "_index": "cgv",         "_type": "movie",         "_id": "_update",         "_score": 0.8630463,         "_source": {           "title": "뮤지컬 〈점프 (JUMP)〉- 서울전용극장(명보아트홀3F)"         }       }     ]   } } #검색2 GET cgv/movie/_search {   "query": {     "match": {       "title": "1인권/입장권]여전히 돈 많은 백수가 되고싶다展"     }   } } #결과2 {   "took": 9,   "timed_out": false,   "_shards": {     "total": 5,     "successful": 5,     "skipped": 0,     "failed": 0   },   "hits": {     "total": 1,     "max_score": 4.8969383,     "hits": [       {         "_index": "cgv",         "_type": "movie",         "_id": "_update",         "_score": 4.8969383,         "_source": {           "title": "여전히 돈 많은 백수가 되고싶다展"         }       }     ]   } }  | cs | 
잘된다. 형태소 분석기 만드시는분들 보면 개인적으로 만드시는데 대단하신분들 인거 같다.
'데이터베이스 > Elasticsearch' 카테고리의 다른 글
| elasticsearch 몇가지 간단 정리 (0) | 2018.10.06 | 
|---|---|
| elasticsearch session timeout 이슈 (0) | 2018.10.06 | 
| elasticsearch multi type 기능 제거 이슈 (0) | 2018.10.06 | 
| Elasticsearch 질의 DSL 정리 (0) | 2018.10.06 | 
| 인덱스 생성 및 데이터 삽입 (0) | 2018.10.05 |