Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Elasticsearch の基礎 / Get Started with Elasticsearch
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Naohisa Murakami
April 23, 2019
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Elasticsearch の基礎 / Get Started with Elasticsearch
Naohisa Murakami
April 23, 2019
Other Decks in Programming
See All in Programming
Workers Cache を知る
syumai
0
220
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
190
新卒PdEのリアル
ryu1013
1
510
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
180
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
120
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
5
4.5k
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3.1k
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5k
Heart of Swift Concurrency
koher
0
960
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
230
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
520
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
360
Featured
See All Featured
Scaling GitHub
holman
464
140k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
600
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
280
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
300
GraphQLとの向き合い方2022年版
quramy
50
15k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
610
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Transcript
Elasticsearch ͷجૅ 2019-04-23 1
τϐοΫε 1. Elasticsearch ͱ 2. Elasticsearch ͷجຊ֓೦ 3. master node
ͱ data node 4. mapping 5. (near) ϦΞϧλΠϜͱ !2
Elasticsearch ͱ ಛ (ʮσʔλੳج൫ߏஙೖʯΑΓɺͨͩ͠ଠࣈಠࣗ) • OSS (Apache Lisence v2) •
υΩϡϝϯτࢦ • ࢄγεςϜ • Ϛϧνςφϯτ • RESTful API • (near) ϦΞϧλΠϜ !3
υΩϡϝϯτࢦ • υΩϡϝϯτ (document) • Elasticsearch Ͱѻ͏σʔλͷ࠷খ୯Ґ • JSON •
id Λ࣋ͭ • (εΩʔϚϨεʹ͑ΔͷͰ) ॊೈͳσʔλͷొ͕Մೳ !4
ࢄγεςϜ • σʔλΛෳ node ؒͰࢄͯ͠อ࣋ɺݕࡧ͢Δ • εέʔϧΞτΛఆͨ͠ઃܭ !5
RESTful API • ͋ΒΏΔૢ࡞͕ REST API Ͱఏڙ͞Ε͍ͯΔ • document ͷՃɺߋ৽ɺআ
• document ͷݕࡧ • ઃఆͷ֬ೝɺมߋ • ϝτϦΫεͷऔಘ !6
RESTful API • ྫ. document ͷՃ readonly ES_INDEX=index1 readonly ES_TYPE=_doc
request=$(cat <<EOF { "name": "Alice", "age": 21, "registered_at": "2019-04-23T03:00:00Z" } EOF ) curl -XPOST -H "Content-Type: application/json" \ http://$ES_HOST:$ES_PORT/$ES_INDEX/$ES_TYPE \ -d "$request" !7
(near) ϦΞϧλΠϜ • ొͨ͠σʔλ΄΅ϦΞϧλΠϜʹݕࡧ݁Ռʹө • σϑΥϧτઃఆͩͱ 1 ඵޙʹө͞ΕΔͬΆ͍ !8
τϐοΫε 1. Elasticsearch ͱ 2. Elasticsearch ͷجຊ֓೦ 3. master node
ͱ data node 4. mapping 5. (near) ϦΞϧλΠϜͱ !9
Elasticsearch ͷجຊ֓೦ • Elasticsearch 1 Ҏ্ͷ node Ͱ cluster
Λߏ͢Δ • cluster ʹ 0 Ҏ্ͷ index ͕ଘࡏ͢Δ • index ʹ 1 ͭҎ্ͷ shard ͕ଘࡏ͢Δ • document ͍ͣΕ͔ͷ shard ʹอଘ͞ΕΔ • client index Λࢦఆͯ͠อଘ͢Δ • อଘઌͷ shard id (ਖ਼֬ʹ routing) ʹΑܾͬͯ·Δ !10
Cluster 1 node, 1 index, 1 shard Node1 0 primary
shard Index1 !11
Cluster 3 node ߏʹ Index1 Node1 Node2 Node3 0 primary
shard !12
Cluster shard Λ 1 -> 4 ʹ Index1 Node1 Node2
Node3 0 1 2 3 primary shard !13
Cluster ֤ shard ʹ 1 replica Ճ Index1 Node1 Node2
Node3 0 1 2 3 0 1 2 3 primary shard replica shard !14
Cluster index Ճ Index1 Node1 Node2 Node3 0 1 2
3 0 1 2 3 primary shard replica shard Index2 !15
ՔಇதͷγεςϜͰʁ • 9 node Ͱ cluster Λߏ • 1 index
ͷΈ, 128 primary shards • దͳ primary shard ѻ͏σʔλʹΑͬͯҟͳΔ • ಈతʹ primary shard Λมߋ͢Δ͜ͱͰ͖ͳ͍ • replica 1 (֤ primary shard ʹ 1 replica ଘࡏ) • id, routing ಠࣗʹઃఆ !16
τϐοΫε 1. Elasticsearch ͱ 2. Elasticsearch ͷجຊ֓೦ 3. master node
ͱ data node 4. mapping 5. (near) ϦΞϧλΠϜͱ !17
master node ͱ data node • ֤ node ىಈ࣌ʹׂΛઃఆ͞ΕΔ •
ׂ1: master eligible (master ީิ) • ͜ͷ node ͷத͔Β master ͕ҰબΕΔ • ׂ2: data (document ͷอଘઌ) • ׂΓͯΒΕͨ shard ͷ document ͷอଘɺݕࡧΛ୲ • master eligible, data ݉Ͱ͖Δ !18
Cluster master node ͱ data node Index1 Node1 Node2 Node3
0 1 2 3 0 1 2 3 Index2 master eligible master data !19
ՔಇதͷγεςϜͰʁ • master eligible node ͕ 3 • data
node ͕ 6 • master eligible ͱ data Λ݉ͨ͠ node ͍ͳ͍ • ຊ൪ڥͰ͚Δ͜ͱ͕ਪ͞Ε͍ͯΔ • master ʹ༨ܭͳෛՙΛ͔͚ͳ͍Α͏ʹ !20
τϐοΫε 1. Elasticsearch ͱ 2. Elasticsearch ͷجຊ֓೦ 3. master node
ͱ data node 4. mapping 5. (near) ϦΞϧλΠϜͱ !21
mapping • index ઃఆͷҰ෦ • document ΛͲͷΑ͏ʹอଘ͢Δ͔ɺindex ͢Δ͔ • ϑΟʔϧυͷܕ
(ྫ. text, keyword, long, date) • analyzer ͷઃఆ • document ʹԠͯࣗ͡ಈͰੜ͞ΕΔ • ࣄલʹఆ͓ٛͯ͘͜͠ͱͰ͖Δ !22
mapping { "name": "Alice", "age": 21, "registered_at": "2019-04-23T03:00:00Z" } •
ࣗಈͰੜ͞ΕΔ mapping ͷྫ (Elasticsearch v7.0) { "index1": { "mappings": { "properties": { "age": { "type": "long" }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "registered_at": { "type": "date" } } } } } Elasticsearch POST /index1/doc GET /index1/mappings !23
mapping • ࣗಈͰੜ͞ΕΔ mapping ͷྫ (Elasticsearch v7.0) { "index1": {
"mappings": { "properties": { "age": { "type": "long" }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "registered_at": { "type": "date" } } } } } age ͷܕ long name ͷܕ text (શจݕࡧ༻) name.keyword Ͱ keyword ͱͯ͠ѻ͑Δ !24
ՔಇதͷγεςϜͰʁ • mapping ࣄલʹఆ͍ٛͯ͠Δ • จࣈྻͯ͢ string ܕͰ not_analyzed ͱͯ͠อଘ
• ݕࡧ࣌ʹอଘͨ͠จࣈྻͷશҰகɺ෦Ұகݕࡧ • શจݕࡧͷΑ͏ͳ༻్Λ͢ΔϑΟʔϧυͳ͍ • (v7.0 Ͱ keyword ܕʹ͋ͨΔઃఆ) !25
ՔಇதͷγεςϜͰʁ • λάʹ͍ͭͯ dynamic_templates Λ༻ { "index1": { "mappings": {
"dynamic_templates": [ { "string-double-tags": { "path_match": "tag.*", "mapping": { "fields": { "double": { "type": "double" } }, "type": "keyword" } } } ] } } } !26
τϐοΫε 1. Elasticsearch ͱ 2. Elasticsearch ͷجຊ֓೦ 3. master node
ͱ data node 4. mapping 5. (near) ϦΞϧλΠϜͱ !27
(near) ϦΞϧλΠϜͱ • Ϣʔβ͕ document ͷอଘΛґཔ͢Δͱ... 1. in-memory buffer ʹॻ͖ࠐΈ
(͜͜ͰϨεϙϯεฦ٫) 2. refresh (͜͜ͰݕࡧʹөɻCRUD ͬͱૣ͍ʁ) 3. flush (͜͜ͰӬଓԽ͞ΕΔɻtranslog ΛΫϦΞ) 4. merge (աڈͷ segment Λ·ͱΊͯσΟεΫݮ) ҙ: v2.x Ͱͷઆ໌Λࢀߟʹ͍ͯ͠Δ !28
refresh_interval • index ઃఆͷ refresh_interval Ͱ refresh ִؒΛઃఆՄೳ # GET
/index1/_settings { "index1": { "settings": { "index": { "refresh_interval": "30s", "number_of_shards": "3", "provided_name": "index1", "creation_date": "1555723945152", "number_of_replicas": "0", "uuid": "3lJEo2YZQWmNzSKjZKDNFw", "version": { "created": "7000099" } } } } } !29
ࢿྉ·ͱΊ • https://github.com/tiqwab/slides/tree/master/ elasticsearch !30