Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Elasticsearch at Wantedly
Search
Seigo Uchida
April 22, 2014
Technology
13
17k
Elasticsearch at Wantedly
2014/04/21 第 4 回 Elasticsearch 勉強会での発表資料。
当日の質問タイム及び懇親会で聞かれたことを追加しています。
Seigo Uchida
April 22, 2014
Tweet
Share
More Decks by Seigo Uchida
See All by Seigo Uchida
Kubernetes Cluster Monitoring
spesnova
2
5.6k
How we monitor microservices at Mercari microservices platform team
spesnova
13
9.9k
Kubernetes RBAC in microservices
spesnova
6
4k
Introduction to kustomize
spesnova
17
37k
Kubernetes 運用設計ガイド / A design guide for Kubernetes in production (Japanese)
spesnova
80
18k
Microservices Monitoring at mercari
spesnova
3
3.8k
Monitoring Kubernetes with Datadog
spesnova
12
4.3k
My Docker Best Practice (2016 Winter Short Version)
spesnova
33
7.4k
CoreOS 運用の所感
spesnova
17
9.2k
Other Decks in Technology
See All in Technology
テストを楽に書きたい
tomorrowkey
1
200
Qdrant を用いた検索改善施策の紹介 / Search Engineering Tech Talk 2024 Summer
visional_engineering_and_design
1
210
LINEヤフー新卒採用 コーディングテスト解説 実装問題編
lycorp_recruit_jp
1
13k
Databricks Appのご紹介
databricksjapan
0
370
Cosmos DB で持続可能な RAG を実現しよう!~ AOAI Dev Day ふりかえりを添えて / Sustainable RAG with Cosmos DB with recap AOAI Dev Day
miyake
0
120
スタサプ ForSCHOOLアプリのシンプルな設計
recruitengineers
PRO
3
700
それでもやっぱり ExpressRoute が好き!
skmkzyk
0
380
塩野義製薬様のAWS統合管理戦略:Organizations設計と運用の具体例
tkikuchi
0
160
Case Study: Concurrent Counting
ennael
PRO
0
130
LeSSはスクラムではない!?LeSSにおけるスクラムマスターの振る舞い方とは / Scrum Master Behavior in LeSS
toma_sm
0
210
TypeScript x Raycast x AIで変える開発者体験
nagauta
1
280
YAPC::Hakodateの映像記録を支える技術
godan
4
380
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
334
57k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
It's Worth the Effort
3n
183
27k
Music & Morning Musume
bryan
46
6.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
130k
Ruby is Unlike a Banana
tanoku
96
11k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
25
660
Atom: Resistance is Futile
akmur
261
25k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Teambox: Starting and Learning
jrom
132
8.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
653
59k
Transcript
Elasticsearch at
SEIGO UCHIDA
!TQFTOPWB w :BIPP+"1"/৽ଔೖࣾ w ݄8BOUFEMZʹδϣΠϯ w ٛͷΠϯϑϥΛ୲ w $IFGͱ)VCPUͱ͔͕͖
!TQFTOPWB
None
γΰτͰίίϩΦυϧਓΛ;͢
None
None
8BOUFEMZ *OD w ݄ઃཱ w ΞϧόΠτɺΠϯλʔϯؚΊ໊ w ໊ͷΤϯδχΞ͕׆༂ w γΰτॆ࣮ԽΞϓϦπʔϧͷఏڙ
w ࣾɺਓ͕͏
ੵۃ࠾༻த https://www.wantedly.com/projects/5106
WantedlyͰESΛ ͲͷΑ͏ʹ͍ͬͯΔͷ͔
ݕࡧର w γΰτ w ձࣾ w Ϣʔβ
γΰτ w ձ໊ࣾ w ۈ w ࣾһ
None
ืू w ืू໊ w ืूৄࡉ w ืू৬छ
None
Ϣʔβ w Ϣʔβ໊ w ࣗݾհจ w ͦͷଞ͍Ζ͍Ζʢޙड़ʣ
None
ΠϯσοΫε w ௨ৗͷݕࡧ༻ΠϯσοΫε w "VUPDPNQMFUF༻ΠϯσοΫε
None
λΠϓ w γΰτλΠϓ w ձࣾλΠϓ w ϢʔβʔλΠϓ
௨ৗͷݕࡧ༻ΠϯσοΫε w υΩϡϝϯτɿສ w ϓϥΠϚϦαΠζɿ(#
"VUPDPNQMFUF༻ΠϯσοΫε w υΩϡϝϯτɿສ w ϓϥΠϚϦαΠζɿ(#
ߏ w 3BJMTPO)FSPLV w &MBTUJDTFBSDIPO&$ w 1PTUHSFTRMPO3%4
FMBTUJDTFBSDISVCZ w UJSFϝϯς͕ऴྃ w TFBSDILJDLUJSFʹґଘ w ެࣜHFNΛ͏ͷ͕༨ܭͳ੍ݶ͕ͳ ͯ͘ྑ͍
Ϋϥελ w &$NTNBMMº w $IFGͰཧ w +7.ׂ.&.ɿࡌ.&.
ར༻ϓϥάΠϯ w )FBE w )2ʢ/PEF%JBHOPTUJDT4UBUT֬ೝʹར༻ʣ w .BSWFM TFOTFͰΫΤϦ࡞ʹར༻ʣ ։ൃڥ ͷΈʣ
w ,VSPNPKJ w *ORVJTJUPSʢ"OBMZ[FSͷڍಈ֬ೝʣ
Ͳ͏ֶͬͯΜ͔ͩ
None
ެࣜϦϑΝϨϯε w ඞཁͳ͜ͱॻ͍ͯ͋Δɺؾ͕͢Δ w ΫΤϦͷྫ͕෦తʹॻ͔Ε͍ͯͯࠔΔ w ݕࡧॳ৺ऀʹશମ૾͕͔ͭΈͮΒ͍ w ͰಡΜͩ
None
&MBTUJDTFBSDI8PSLTIPQ w શମ૾Λ௫Έͭͭɺ࣮ࡍʹ৮ΔͷͰΠ ϝʔδ͕௫Ίͨ w IUUQTTQFBLFSEFDLDPNEBEPPOFUFMBTUJDTFBSDIXPSLTIPQ
None
&MBTUJDTFBSDIνϡʔτϦΞϧ w ༻ޠɺશମ૾͕௫Έ͍͢ w ίϯςΩετ͕͋Γ࣮ફత w IUUQDPEFIBUFOBCMPHDPNFOUSZ
͜ͷຊ͕ͬͱૣ͘ग़ͯΕʜ
ۤ࿑ͨ͠ͱ͜Ζ
Ϣʔβʔݕࡧ w ϓϩϑΟʔϧ߲͕ଟ͍ w ֤߲ຖʹϓϥΠόγʔϨϕϧ ͕͋Δ w NBQQJOHRVFSZෳࡶʹ
Ͳ͏ͬͯ ES Ͱ ACL Λ࣮ݱͯ͠Δ͔ w ྫ͑ɺϓϩϑΟʔϧͷʮ໊લʯʮॴଐʯʮॴ ࡏʯΛجຊใͷηοτͱͯ͠ϓϥΠόγʔ ϨϕϧʮҰൠެ։ʯͱ͍ͯͨ͠ͱ͢Δ w
࠷ॳ/FTUFEEPDVNFOUΛͬͯදݱ͠ ͍ͯͨ
"properties": {! "basic_privacy": {! "type": "nested"! },! "properties": {! "name":
{! "type": "string"! },! "working_for": {! "type": "string"! },! "location": {! "type": "string"! },! "privacy_level": {! "type": "string"! }! }! }! mapping
Ͳ͏ͬͯ ES Ͱ ACL Λ࣮ݱͯ͠Δ͔ w ͔͠͠ɺ/FTUFEͩͱͰ͖ͳ͍͜ͱʢϋΠϥΠτͳͲʣ ͕ग़ͯ͘ΔͷͰϑϥοτͳߏͰɺϓϥΠόγʔϨϕ ϧΛදݱ w
ܕ@σʔληοτ@@ϓϩύςΟͷΑ͏ʹϚοϐ ϯά w ࠷ॳͷܕ͕ඞཁͳͷɺEBUFJOUFHFSͳͲ TUSJOHҎ֎ʹTJNQMF@RVFSZΛ͏ͱFSSPSͱͳΔͨ Ί
mapping query {! "query": {! "simple_query_string": {! "query": <QUERY>,! "fields":
["s_basic__*"],! "default_operator": "and"! }! }! },! "filter": {! "term": {! "basic_privacy": <PRIVACY_LEVEL>! }! }! }! "properties": {! "basic_privacy": {! "type": "string"! },! "s_basic__name": {! "type": "string"! },! "s_basic__working_for": {! "type": "string"! },! "s_basic__location": {! "type": "string"! }! }!
Ͳ͏ͬͯ ES Ͱ ACL Λ࣮ݱͯ͠Δ͔ w ݁ՌతʹɺOFTUFEΛΘ͟ΔΛಘͳ͍໘ ͕ग़ͯདྷͯϑϥοτͳϓϩύςΟͱOFTUFE Λซ༻͍ͯ͠Δ͕ɺࠓճͦ͜লུ
࣭λΠϜ
4PMS$MPVETFBSDIධՁ্ͨ͠Ͱ &4ʹͨ͠ͷ͔ w ʮ༑ୡͱͷܨ͕ΓʯΛՃຯͯ͠ݕࡧͰ͖Δ͔ͱ͍͏͜ͱͰɺάϥϑ %#ͷ/FPKͱҰൠతͳݕࡧͱͯ͠&4Λൺֱͯ͠ɺ&4ͷํ͕அ વύϑΥʔϚϯε͕ྑ͔ͬͨ w 4PMSʹ͍ͭͯ4PMSϢʔβ͔Βࠓ͔Β͏ͳΒ&4ͱ͍͏Λฉ͍ ͍ͯͨ w
ར༻Ϣʔβʢ(JU)VC GPVSTRVBSF 4PVOE$MPVEͳͲʣࢀߟʹ͠ ͨ w ݁Ռతʹɺ4PMSʹͳ͍OFTUFE QBSFOUDIJMEEPDVNFOUΛͬͯ ͍ΔͷͰ&4Ͱྑ͔ͬͨ
։ൃڥͰ&4Λ͏ͱ NBQQJOHͳͲόϥόϥͰਏ͘ͳΒͳ͍͔ w #PPUTUSBQεΫϦϓτͱ͍͏ͷΛ༻ҙͯ͠HJUDMPOFޙ ͷηοτΞοϓʢMPDBMʹ&4ΛೖΕΔͳͲʣΛࣗಈԽ͠ ͍ͯΔ w .BQQJOHυΩϡϝϯτͷՃηοτΞοϓεΫϦϓ τΛ༻ҙͯ͠ɺϝϯόʔ͝ͱͷڥͷ͕ࠩग़ͳ͍Α͏ʹ ͍ͯ͠Δ
! #! # Check for Elasticsearch! #! if test !
$(which elasticsearch)! then! echo " x You need to install ElasticSearch:"! echo " + Installing Elasticsearch..."! brew install elasticsearch! else! echo " + ElasticSearch found."! fi! ! #! # Check for Elasticsearch version! #! ES_VERSION=$(elasticsearch -v | cut -d' ' -f2 | cut -d'.' -f1)! if test ! $ES_VERSION -eq 1! then! echo " x You need to upgrade elasticsearch."! brew upgrade elasticsearch! else! echo " + Your Elasticsearch version is correct."! fi! ! if test -d /usr/local/var/lib/elasticsearch/plugins/marvel! then! echo " + Elasticsearch Plugin Marvel found."! else! echo " + Installing Elasticsearch Plugins Marvel"! plugin --install elasticsearch/marvel/latest! fi! bootstrap script Ұ෦ൈਮ $ script/bootstrap! ! Wantedly! ! γΰτͰίίϩΦυϧਓΛ;͢! ! + Your Elasticsearch version is correct.! + ElasticSearch Plugin HQ found.! + ElasticSearch Plugin head found.! + ElasticSearch Plugin Kuromoji found.! + ElasticSearch Plugin Inquisitor found.! + ElasticSearch Plugin Marvel found.! ! Good work. We're ready.! ! Run 'elasticsearch' to start elasticsearch.! And you can see elasticsearch webui plugins 'locahost:9200/_plugin/head/'! ࣮ߦ݁Ռ γϯϓϧͳγΣϧεΫϦϓτɻelasticsearch ϓϥάΠϯ͕Πϯετʔϧ͞ΕͯΔ ͔ΛνΣοΫͯ͠͞Εͯͳ͍ͳΒΠϯετʔϧ͢Δɻ ʢ࣮ࡍͷεΫϦϓτͰ elasticsearch Ҏ֎ͷηοτΞοϓͬͯΔʣ
elasticsearch-ruby Λͬͨ setup script ྫ class ES! def self.client! @client
||= Elasticsearch::Client.new({! url: ES.url,! log: true! })! end! end! ! ES.client.indices.create({! index: "index_name",! body: {! settings: {! analysis: {! filter: {! ...! },! tokenizer: {! ...! },! analyzer: {! ...! }! }! }! }! })! ! ES.client.indices.put_mapping({! index: “index_name”,! type: 'user',! body: {! company: {! _id: { path: 'id' },! _timestamp: { enabled: true, path: 'updated_at', store: true },! _source: { enabled: true },! _all: { enabled: true, analyzer: 'kuromoji_analyzer' },! properties: {! name: { type: 'string', store: true, index: 'analyzed', analyzer: 'kuromoji_analyzer' },! . . .! }! }! }! })! ! ! User.find_in_batches do |users|! body = users.map do |user|! {! index: {! _index: "index_name",! _type: 'user',! _id: user.id,! data: user.elasticsearch_data,! }! }! end! ES.client.bulk body: body! end!
εΩʔϚมߋ࣌ʹαʔϏεʹӨڹΛ༩͑ͳ͍Α͏ɺ Ͳ͏ΫϥελΛߋ৽ͯ͠Δ͔ w #MVF(SFFO%FQMPZNFOUΈ͍ͨͳ͜ͱ ʢ࣮ࡍ৭ʣΛ͍ͬͯΔ
blue-es.wantedly.com blue-es-elb Nginx + ES Nginx + ES blue-es-cluster green-es.wantedly.com
green-es-elb Nginx + ES Nginx + ES green-es-cluster چεΩʔϚ ৽εΩʔϚ
&4ͷ#MVF(SFFO%FQMPZNFOU w CMVFFTFMC HSFFOFTFMCͷΑ͏ʹ&-# αϒυϝΠϯΛͭ༻ҙ͓ͯ͘͠ w $IFGͰlFMBTUJDTFBSDISPMF lHSFFOzFOWJSPONFOUͱͯ͠&4αʔόΛߏ ங͢ΔͱɺΫϥελϦϯάɺ&-# HSFFOFTFMC
ͷొ·ͰࣗಈͰηοτ Ξοϓ͞ΕΔΑ͏ʹͯ͠Δɻ͘Β͍ɻ w ࣾϝϯόʔͷΈΞΫηεՄೳͳڥʹ࠷৽ͷ3BJMTΞϓϦʢ&4ͷ .BQQJOHΛؚΉʣΛσϓϩΠޙɺ͔ͦ͜ΒHSFFOFTDMVTUFSʹ৽εΩʔϚ ͷΠϯσοΫε࡞ɺυΩϡϝϯτՃΛߦ͏ w Ϋϥελʹσʔλ͕ೖͬͨΒɺຊ൪ڥͷ3BJMT࠷৽ʹͨ͠ޙɺ3BJMT͔Β ར༻͢Δ&4ͷΤϯυϙΠϯτʢڥมͰઃఆ͍ͯ͠ΔʣΛΓସ͑ͯσϓ ϩΠྃ
ࠓޙͷ՝
ࠓޙͷ՝ w ύϑΥʔϚϯεͷ্ w ϢʔβʔݕࡧͷϋΠϥΠτ w ࣙॻ͏ w ݕࡧਫ਼
͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ