Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
ElasticsearchʹΑΔ શจݕࡧͷ࣮ in Rails #railsdm by FUJI Goro (gfx)
Slide 2
Slide 2 text
ࠓ͢͜ͱ • ΣϒαʔϏεͰશจݕࡧΛఏڙ͢Δͱ͖ʹ ͱ͖ʹߟ͑Δ͜ͱ • ElasticsearchʹΑΔશจݕࡧʹ͓͚Δ࣭ͷ ੍ޚʹ͍ͭͯ
Slide 3
Slide 3 text
ࠓ͞ͳ͍͜ͱ • Elasticsearch vs ଞͷશจݕࡧΤϯδϯ • ϚωʔδυαʔϏε vs ࣗલ • ಛఆͷ elasticsearch client library ͷ • e.g. elasticsearch-rails, searchkick, elastomer-client
Slide 4
Slide 4 text
ൃදऀʹ͍ͭͯ • ໊લ: gfx / ౻ޗ • ใڞ༗αʔϏεKibelaΛ։ൃ͍ͯ͠Δ • Kibela Ruby on RailsαʔϏε • લճͷrailsdmͰʮϚϧνςφϯτɾΣϒΞϓϦέʔ γϣϯͷ࣮ફʯͱ͍͏ൃදΛͨ͠ • KibelaͰ Amazon Elasticsearch Service Λར༻
Slide 5
Slide 5 text
ΣϒαʔϏεͰશจݕࡧΛ ఏڙ͢Δͱ͖ʹߟ͑Δ͜ͱ
Slide 6
Slide 6 text
શจݕࡧ in ΣϒαʔϏε • ࣭Λ্͛Δʹఔίετֻ͕͔Δ • ≒ίετΛֻ͚Δ΄Ͳʹ࣭Λ্͛ΒΕΔ • Ͳͷ͘Β͍ίετΛֻ͚ΒΕΔ͔ͰΔ͜ͱ͕ ͔ͳΓมΘΔ • ίετΛֻ͚ΒΕͳ͍ͳΒͦͦશจݕࡧ ෆཁ͔͠Εͳ͍
Slide 7
Slide 7 text
ݕࡧͷ࣭ • ݕࡧͷ࣭Ұൠʹʮద߹ʯͱʮ࠶ݱʯ ͰݟΔ • ద߹ʮਖ਼֬ੑʯͱ͍͏ • ࠶ݱʮཏੑʯͱ͍͏
Slide 8
Slide 8 text
ద߹ vs ࠶ݱ • ద߹:ʮݕࡧ͞Εͨద߹จॻͷ ÷ ݕࡧ݁Ռͷจॻͷ ʯ • ద߹͕ߴ͍ͱʮݕࡧ݁Ռͷଟ͕͘ద߹ੑ͕ߴ͍ʯ • ࠶ݱ:ʮݕࡧ͞Εͨద߹จॻͷ ÷ શରจॻதͷਖ਼ ղจॻͷʯ • ࠶ݱ͕ߴ͍ͱʮద߹ੑͱ͔͘औΓ͜΅͠ͳ͍ʯ
Slide 9
Slide 9 text
ద߹ͱ࠶ݱͷࢉग़ • ԿΛ࣋ͬͯʮద߹ʯͱ͢Δ͔Ϣʔβʔͷ಄ͷதʹ ͷΈ͋Δ • ≒ ಉ͡ݕࡧΩʔϫʔυͰϢʔβʔ͝ͱʹٻΊΔ ͷҟͳΔՄೳੑ͕͋Δ • ࣮ࡍͷαʔϏεͰଌఆ͢Δ͜ͱෆՄೳ • ⇢ϢʔβʔͷߦಈΛੳͯ͠ධՁ͢Δඞཁ͕͋Δ
Slide 10
Slide 10 text
ద߹ͱ࠶ݱͰॏࢹ͢Δͷʁ • Ұൠʹద߹ͱ࠶ݱτϨʔυΦϑͷ͕ؔ͋ Δͱ͍ΘΕΔ • ͲͪΒ͕ॏཁ͔αʔϏεͷੑ࣭ʹΑΔ • KibelaͷΑ͏ͳاۀͷจॻݕࡧͰʮऔΓ͜΅ ͠ ≒ όάʯͱೝࣝ͞ΕΔ • ͭ·Γ࠶ݱʮ࠷ݶकΔ͖࣭ʯͰ͋Δ
Slide 11
Slide 11 text
ElasticsearchʹΑΔશจݕࡧ ʹ͓͚ΔݕࡧείΞͷߟ͑ํ
Slide 12
Slide 12 text
Elasticsearchͱ • શจݕࡧΤϯδϯ • SQLͷLIKEݕࡧͱͷҧ͍: • ܗଶૉղੳޙͷ୯ޠͰݕࡧͰ͖Δ • ਖ਼نԽ͞Εͨ୯ޠͰݕࡧͰ͖Δ • ෳࡶͳείΞʹجͮ͘ιʔτ͕Ͱ͖Δ
Slide 13
Slide 13 text
Elasicsearch༻ޠ RDBMS Table Record Column Elasticsearch Index Document Field ※ Elasticsearch v5·Ͱ table = type ͱઆ໌͞Ε͖͕ͯͨ v6 Ͱtypeඇྭɺ v7 Ͱআ͞ΕΔͷͰҙ
Slide 14
Slide 14 text
ܗଶૉղੳ
Slide 15
Slide 15 text
ܗଶૉղੳͯ͠ݕࡧ • શจݕࡧͷߴԽͷͨΊʹసஔΠϯσΫεͳͲͷ ΞϧΰϦζϜΛ͍͍ͨ • సஔΠϯσΫεͷͨΊʹೖྗ͞ΕΔจষΛదͳ ୯ҐͰׂ͢Δඞཁ͕͋Δ • ຊޠͷΑ͏ʹ୯ޠͷ۠Γ͕͖ͬΓ͠ͳ͍ݴ ޠͷ߹N Gram and/or ܗଶૉղੳͰׂ͢Δ
Slide 16
Slide 16 text
N Gram • N௨ৗ2͔3 • 2 gram ͷ߹ɺʮ͜ΜʹͪʯΛ • [“͜Μ”, “Μʹ”, “ʹͪ”, “ͪ”] ʹ͚Δ
Slide 17
Slide 17 text
ܗଶૉղੳ • ʮ౦ژʹҾͬӽͨ͠ʯΛ • [“౦ژ”, “ʹ”, “Ҿͬӽ͠”, “ͨ”] ͳͲʹׂ ͢Δ • ࢺʢ໊ࢺ, ܗ༰ࢺʣใ͕ར༻Ͱ͖ΔͷͰɺ ޙͷਖ਼نԽͰͦͷใΛར༻
Slide 18
Slide 18 text
LIKEݕࡧͱͷࠩ: ܗଶૉղੳฤ • “౦ژʹҾͬӽͨ͠” LIKE “%ژ%” • Ϛον͢Δ • [“౦ژ”, “ʹ”, “Ҿͬӽ͠”, “ͨ”].include?(“ژ ”) • Ϛον͠ͳ͍
Slide 19
Slide 19 text
ܗଶૉղੳͱN Gramͷࠩ • ͨͱ͑ʮژʯͰʮ౦ژʯΛؚΉจॻΛ… • ܗଶૉղੳϕʔεͩͱݕࡧͰ͖ͳ͍ • ͭ·Γద߹ͷ໘Ͱ༏Ε͍ͯΔ • N GramϕʔεͩͱݕࡧͰ͖Δ • ͭ·Γ࠶ݱͷ໘Ͱ༏Ε͍ͯΔ
Slide 20
Slide 20 text
ਖ਼نԽ
Slide 21
Slide 21 text
ͳͥਖ਼نԽ͕ඞཁ͔ • ܗଶૉղੳʴసஔΠϯσΫεʹΑΔݕࡧͷࣜ Խ: [“Ҿͬӽ͠”, “ͨ”].include?(“Ҿͬӽ͠”) • “Ҿӽ”, “Ҿӽ͠” ಉ༷ʹݕࡧ͍ͨ͠ ⇢ ਖ਼نԽ
Slide 22
Slide 22 text
ܗଶૉղੳͱਖ਼نԽ • ܗଶૉղੳث͕ࣙॻͱࢺใΛͬͯਖ਼نԽ͢Δ • Elasticsearchͷ߹kuromoji plugin͕ຊޠͷܗଶૉղੳ ͱਖ਼نԽΛαϙʔτ • kuromoji_baseform: “ҿΈ” ⇢ “ҿΉ” • kuromoji_stemmer: “αʔόʔ” ⇢ “αʔό” • kuromoji_number: “ඦԁ” ⇢ “100ԁ”
Slide 23
Slide 23 text
είΞϦϯά
Slide 24
Slide 24 text
ݕࡧॱͷॏཁੑ • ͨͱ͑ɿʰژʱͰʰ౦ژʱͱ͍͏จॻ ώοτͯ͠΄͍͕͠ɺʰژʱͰώοτ͢ Δจॻ͕͕͋ΔͳΒͦͪΒΛ্Ґʹ͍࣋ͬͯ ͖͍ͨ • ͭ·Γߴ͍࠶ݱΛҡ࣋ͭͭ͠ݕࡧ݁Ռͷ্ ҐʮΑΓద߹͢ΔͱࢥΘΕΔʯจॻʹͨ͠ ͍
Slide 25
Slide 25 text
୯ޠׂ๏ʹΑΔॏΈ͚ • ܗଶૉղੳͰׂ͢Δͱద߹ߴ͘ͳΓ͕ ͕ͪͩ࠶ݱ͘ͳΓ͕ͪ • N GramͰׂ͢Δͱ࠶ݱߴ͘ͳΓ͕ͪͩ ͕ద߹͘ͳΓ͕ͪ • ⇢είΞϦϯάͷࡍʹॏΈ͚Λ͢ΕΑ͍
Slide 26
Slide 26 text
ElasticsearchͰͷ࣮ํ๏ • elasticsearch-model Ͱͷσʔλιʔεఆٛ UJUMFLVSPNPKJͰ ׂ͢Δ UJUMF@OHSBN/ (SBNͰׂ͢Δ
Slide 27
Slide 27 text
ϑΟʔϧυ͝ͱͷॏΈ͚ • ElasticsearchͰϑΟʔϧυ͝ͱʹॏΈ͚ ΛઃఆͰ͖Δ
Slide 28
Slide 28 text
ͦͷଞͷείΞϦϯάख๏ • Phrase Match / ϑϨʔζϚον • Field Value Factor / ϑΟʔϧυ • Decay / είΞͷݮਰ
Slide 29
Slide 29 text
Phrase Match • TwitterݕࡧGoogleݕࡧͰμϒϧΫΥʔτͰғΜͩͱ͖ʹ ʮϑϨʔζͦͷͷʯ͕ݕࡧରʹͳΔͷ͕Phrase Match • Kibelaͷ߹ɺϑϨʔζʹϚονͨ͠ΒείΞΛϒʔετ ͍ͯ͠Δ • ྫ:ʮঁਆసੜʯͰݕࡧ͢ΔͱʮਅɾঁਆసੜIII NOCTURNEʯͷ΄͏͕ʮҟੈքʹঁਆͱͯ͠సੜ͠ ͨʯΑΓείΞ͕ߴ͘ͳΔ
Slide 30
Slide 30 text
Field Value Factor • ಛఆͷϑΟʔϧυͷͰείΞΛϒʔετͤ͞ Δػೳ • Kibelaͷ߹ɺϥΠΫͱτϥοΫόοΫΛ Field Value Factorͱͯ͠ө͍ͤͯ͞Δ • ͭ·ΓʮΑ͘ϥΠΫ͞ΕΔจॻʯʮΑ͘Ϧ ϯΫ͞ΕΔจॻʯͷείΞ͕ߴ͍
Slide 31
Slide 31 text
Decay • Field Value FactorͷٯͰɺಛఆϑΟʔϧυ ͰείΞΛݮਰͤ͞Δػೳ • KibelaͰɺจॻͷλΠϜελϯϓΛར༻͠ ͕ͯ࣌ؒܦͭ΄ͲʹείΞ͕ݮਰ͢ΔΑ͏ʹ ͍ͯ͠Δ
Slide 32
Slide 32 text
DecayͷΠϝʔδ • origin = now / timestampաڈͷҰͱ͢Δ
Slide 33
Slide 33 text
·ͱΊ • શจݕࡧͷ࣭ʮద߹ʯʮ࠶ݱʯʮε ίΞϦϯάʯͰߟ͑Δ • ʮద߹ʯͱʮ࠶ݱʯ୯ޠׂ๏ʹΑͬ ͯվળͰ͖Δ • ʮείΞϦϯάʯ༷ʑͳཁૉ͕͋ΔͷͰશ จݕࡧΤϯδϯͷυΩϡϝϯτΛख़ಡ͢Δ