480. analysis
•STEP 1. Character filtering
- 특정 문자들을 인식하여 검색에 사용할 수 있는 적합한 문자로 변환하는 작업
- ex) mapping char filter, html strip char filter, pattern replace char filter
•STEP 2. Tokenizing
- 문장을 검색에 사용가능한 조각(token)으로 쪼개는 작업
- ex) whitespace tokenizer, ngram tokenizer, keyword tokenizer
•STEP 3. Token filtering
- 하나의 토큰을 입력으로 받아 수정하거나 삭제, 필요한 경우 토큰을 추가한다.
- ex) lowercase token filter, ascii folding token filter, length token filter
•STEP 4. Token indexing
- Token filtering 까지 거친 토큰들은 최종적으로 인덱싱된다.
- 이 토큰들이 바로 inverted index를 구성하는 요소이다.
이 네 가지 요소들이 결합된 세트가 바로 Analyzer 이다.
486. example
•STEP 1. Character filtering (mapping char filter)
“I love you and me”
•STEP 2. Tokenizing (whitespace tokenizer)
“I”, “love”, “you”, “and”, “me”
•STEP 3. Token filtering (lowercase + stop + synonym token filter)
“i”, “love”, “you”, “me”, “like”
•STEP 4. Token indexing
indexing [“i”, “love”, “you”, “me”, “like”]
검색시에는 쿼리의 종류에 따라 동일한 analysis 과정이 수행되거나
그렇지 않을 수도 있다.
“I love u me”
indexing request
589. documents
$ curl -XPUT localhost:9200/blog/post/12345678?pretty -d '{
title: How can use Elasticsearch?,
body: Some text to be here ...
[... 이하생략 ...]
}'
참고.
607. 한다.
Node 1
1 2 3 4 5
Node 2
4 5 1 2 3
2. Hashing the document ID (ex. 12345678 - hash function - 4)
[Hash range == # of shards]
1. Indexing request
3. Move and index the document to the target primary shard
4. Index the document to the replica
5. Send response
이렇게 해싱된 값을 “routing value”
라고 하며, 이 값을 이용하여 문서를 특
정 샤드에 할당하는 작업을 “routing”
이라고 한다.
612. documents
$ curl -XPOST localhost:9200/blog/post/12345678/_update -d '{
doc: {
new_title: This is a new title.
}
}'
1. Sending a partial document
Three
616. documents
$ curl -XPOST localhost:9200/blog/post/12345678/_update -d '{
script: ctx._source.title = new_title,
params: {
new_title: This is a new title.
}
}'
3. Using script
2. Using upsert
$ curl -XPOST localhost:9200/blog/post/12345678/_update -d '{
doc: {
new_title: This is a new title.
},
upsert: {
name : This is a new title.,
date: 2014-12-04T19:00
}
}'
= The most simple way
= Insert if the document does not exist. Upsert = Update + Insert
= Can handle complex situations (default script language : MVEL)
622. data
1. Delete Document(s)
$ curl -XDELETE localhost:9200/blog/post/12345678
$ curl -XDELETE localhost:9200/blog/post/_query?q=elasticsearch
2. Delete Type
$ curl -XDELETE localhost:9200/blog/post/_mapping
3. Delete Index
$ curl -XDELETE localhost:9200/blog
4. Close/Open Index
$ curl -XPOST localhost:9200/blog/_close
$ curl -XPOST localhost:9200/blog/_open
이 두가지 방식은 문서가
검색되지 않도록 mark만
하고, 실제 삭제 작업은 비
동기적으로 추후에 수행된
다.
이 방식은 파일을 실시간
으로 삭제한다.
인덱스를 close 하면 데
이터를 읽거나 쓸수 없다.
이러한 방식은 주로 로그
데이터 관리 등에 사용한
다.
843. aggregations
Metrics
Buckets
• 최대값, 최소값, 평균, 표준편와 같은 일반적인 통계수치를 집계
• 하위에 다른 aggregation을 중첩하여 사용할 수 없다.
• ex) 쇼핑몰 상품의 카테고리별 평균 가격, 웹사이트의 Unique Visitor 통계
• 검색결과를 특정 기준에 의하여 여러 버킷으로 분류
• 하위에 다른 aggregation을 중첩하여 사용할 수 있다.
• ex) 산업군별 연봉 통계 및 증가 추이
Single-bucket aggregations
Multi-bucket aggregations
ex) global, filter, missing aggregations
ex) terms, significant terms, range, histogram aggregations
849. aggregations
Aggregation은 항상 query의 결과에 대해서 수행된다.
query
aggregations
검색 결과
집계 결과
Filter 또는 Post-filter를 추가한다면?
Aggregations 대상을 필터링 하고 싶다면?
filtered query
aggregations
검색 결과
집계 결과
query
aggregations
검색 결과
집계 결과
filter / post_filter