ES05 데이터 분석
데이터 분석
무엇을?
ES에서 분석은 도큐먼트를 색인하기 전에 수행하는 과정으로 많은 단계를 거친다.
그리고 검색을 실행하는 동안에도 분석이 수행된다 (match/O, term/X)
1. 문자열 필터링 - 문자 필터를 이용하여 문자를 변환한다.
예) & => and
2. 텍스트를 토큰으로 분리 - 텍스트를 한개 이상의 토큰의 집합으로 분해한다.
예) i am a boy = > [i,am,a,boy] ; 토크나이저 이용
3. 토큰 필터링 - 토큰 필터를 이용 개별 토큰으로 변환한다.
예) 소문자,불용어,동의어 ; 토큰 필터
4. 토큰 색인 - 토큰을 색인에 저장한다.
예) 루씬에서 역색인을 진행한다.
어떻게 적용?
색인이 생성될 때 분석이 진행되기 때문에 색인을 만들때 setting에 분석기 정보를 명시하고 mapping을 만들때 각 필드에 적절한 분석기를 적용할 수 있다.
curl -XPOST 'localhost:9200/myindex' -d '{
"setting":{
"number_of_shards": 2,
"number_of_replicas": 1,
"index":{
"analysis":{
"analyzer":{ // 분석기
"myCustomAnalyzer":{
"type":"custom",
"tokennizer":"myCustomTokenizer",
"filter":["myCusteomFilter1","myCustomFilter2"],
"char_filter":["myCustomCharFilter"]
},
"tokenizer": { // 토크나이저
"myCustomTokenizer": {
"type": "letter"
}
}, // End of analyzer
"filter": { // 사용자 지정 필터
"myCustomFilter1":{
"type": "lowercase"
},
"myCustomFilter2":{
"type": "kstem"
}
}, // End of filter
"char_filter":{ // 문자 필터
"myCustomCharFilter":{
"type": "mapping",
"mappings": ["ph=>f", "u=>you"]
}
} // End of char_filter
} // End of analysis
}, // End of index
// 매핑 정의
"mapping": {
"document": {
"properties": {
...
"description":{
"type": "string",
"analyzer": "myCustomAnalyzer"
}
...
}
}
} // End of mapping
}'