5. • 가사에 “사랑”을 포함하는 곡을 찾는다면
검색이란
title: 1
lyrics: …..
…………….
……..
문서
title lyrics
1 ……………………………
2 ……………………………
… ……………………………
table in RDBMS
색인
검색
• “사랑”을 포함하는 row full scan
=> 1M
term docs
사랑 1, 7, 3, …
행복 23, 54, …
… ……………………………
inverted index in search engine
색인
• “사랑”을 포함하는 row full scan
=> 1
검색
11. 개요
• 분산 환경의 문서 지향(distributed document-oriented)
– 데이터 저장소(data store)
• 수백 대의 서버로 scale out
• PB 급의 데이터 저장
• document(serialized JSON object) 기반 data structure
• partial document update 지원
– document는 근본적으로 수정이 불가능(immutable)
– update = replacement(internally)
– 검색 엔진(search engine)
• 루씬(lucene)을 내부 엔진으로 사용
• 모든 필드를 indexing하여 검색 가능
– 실시간 분석 플랫폼(real-time analytic platform)
• aggregation 지원
• approximate aggregation = (big data + real-time analysis) – precision
– 빅 데이터를 정확도를 낮춰서 실시간으로 분석
storing indexing
searching
analyzing
filtering ordering
aggregation
저장
검색
분석
13. node & cluster
• 0개의 index를 가진 > 1개의 node로 구성된 > 1개의 cluster
– node: 실행중인 elasticsearch instance
• master node
– 클러스터를 관리
» index 추가 / 삭제
» node 추가 / 삭제
– 투표를 통해 master node 선출
– document 단위의 변경 또는 search는 모두 데이터 노드에서 이루어지므로
master node는 bottleneck이 되지는 않음
– cluster: 동일한 cluster.name을 가지는 node들의 집합
14. 참고) cluster / node / index
https://github.com/socurites/elasticsearch-foot
15. index & shard
• 3개의 primary shard로 구성된 > 1개의 index를 가진 > 1개의 node로 구성된
1개의 cluster
– index: 관련성이 있는 데이터의 저장 단위
• 물리적인 shard에 대한 논리적인 이름 공간
– shard: index의 데이터 일부를 저장하여 전체 index를 구성
• indexing된 document가 실제 저장되는 곳
• document들은 여러 shard에 분산되어 저장되므로 scale out을 지원
• primary shard
– 모든 document 단 하나의 primary shard에 위치
– primary shard의 개수는 index를 생성할 때 결정되며 바꿀 수 없음 (default: 5)
• replica shard
– primary shrad의 복사본
– 장애 발생시 recovery / searching에 대한 concurrent read 보장
16. 1 replica
• 3개의 primary shard와 1개의 replica로 구성된 > 1개의 index를 가진 >
2개의 node로 구성된 1개의 cluster
17. scale out – shard reallocation
• 3개의 primary shard와 1개의 replica로 구성된 > 1개의 index를 가진 >
3개의 node로 구성된 1개의 cluster
– shard는 새로운 노드로 재할당되어, 새로 추가된 computing power를 완전히 활용할
수 있음
18. 2 replica
• 3개의 primary shard와 2개의 replica로 구성된 > 1개의 index를 가진 >
3개의 node로 구성된 1개의 cluster
19. recovery on failure
• 3개의 primary shard와 2개의 replica로 구성된 > 1개의 index를 가진 >
2개의 node로 구성된 1개의 cluster
– master node 1이 shutdown된 경우,
• primary node selection
– node 2가 새로운 primary node가 선출된다
• recovering primary shard
– node 1에 위치한 primary shard 1, 2가 사라짐
– replica node를 새로운 primary shard로 지정
21. flush, refresh, optimize
• elasticsearch에서
– search는 near real-time: indexing한 document를 기본적으로 1s 이후 search 가능
– CRUD는 real-time
– data persistence를 보장
– delete operation을 하더라도 disk가 바로 해제되지 않음
• Why?
– refresh
– flush
– optimize
22. dynamically updatable indices
• index의 immutable한 장점은 그대로 유지한 채, index를 수정 가능하게 하기
– “여러 개의 index를 사용하자”
• 기존의 커다란 inverted index는 그대로 유지
• 새로운 document는 주기적으로 새로운 index로 생성
• search 요청 발생시, 여러 개의 index를 차례대로 검색한 후 결과를 병합하여 리턴
– segment: 이러한 여러 개의 index들 중 하나
• 용어 정리
– index = segements + commit point
– commit point
= 현재 segment 목록
index
shard
segment