Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elasticsearchによる 全文検索の実装 in Rails

Elasticsearchによる 全文検索の実装 in Rails

Rails Developers Meetup 2018 (#railsdm) の発表資料です。

FUJI Goro

March 24, 2018
Tweet

More Decks by FUJI Goro

Other Decks in Technology

Transcript

  1. ࠓ೔࿩͞ͳ͍͜ͱ • Elasticsearch vs ଞͷશจݕࡧΤϯδϯ • ϚωʔδυαʔϏε vs ࣗલ •

    ಛఆͷ elasticsearch client library ͷ࿩ • e.g. elasticsearch-rails, searchkick, elastomer-client
  2. ൃදऀʹ͍ͭͯ • ໊લ: gfx / ౻ޗ࿠ • ৘ใڞ༗αʔϏεKibelaΛ։ൃ͍ͯ͠Δ • Kibela͸

    Ruby on Rails੡αʔϏε • લճͷrailsdmͰ͸ʮϚϧνςφϯτɾ΢ΣϒΞϓϦέʔ γϣϯͷ࣮ફʯͱ͍͏ൃදΛͨ͠ • KibelaͰ͸ Amazon Elasticsearch Service Λར༻
  3. ద߹཰ vs ࠶ݱ཰ • ద߹཰:ʮݕࡧ͞Εͨద߹จॻͷ਺ ÷ ݕࡧ݁Ռͷจॻͷ ਺ʯ • ద߹཰͕ߴ͍ͱʮݕࡧ݁Ռͷଟ͕͘ద߹ੑ͕ߴ͍ʯ

    • ࠶ݱ཰:ʮݕࡧ͞Εͨద߹จॻͷ਺ ÷ શର৅จॻதͷਖ਼ ղจॻͷ਺ʯ • ࠶ݱ཰͕ߴ͍ͱʮద߹ੑ͸ͱ΋͔͘औΓ͜΅͠͸ͳ͍ʯ
  4. Elasicsearch༻ޠ RDBMS Table Record Column Elasticsearch Index Document Field ※

    Elasticsearch v5·Ͱ͸ table = type ͱઆ໌͞Ε͖͕ͯͨ v6 Ͱtype͸ඇ঑ྭɺ v7 Ͱ࡟আ͞ΕΔͷͰ஫ҙ
  5. ܗଶૉղੳ • ʮ౦ژ౎ʹҾͬӽͨ͠ʯΛ • [“౦ژ౎”, “ʹ”, “Ҿͬӽ͠”, “ͨ”] ͳͲʹ෼ׂ ͢Δ

    • ඼ࢺʢ໊ࢺ, ܗ༰ࢺʣ৘ใ͕ར༻Ͱ͖ΔͷͰɺ ޙͷਖ਼نԽͰͦͷ৘ใΛར༻
  6. Phrase Match • Twitterݕࡧ΍GoogleݕࡧͰμϒϧΫΥʔτͰғΜͩͱ͖ʹ ʮϑϨʔζͦͷ΋ͷʯ͕ݕࡧର৅ʹͳΔͷ͕Phrase Match • Kibelaͷ৔߹ɺϑϨʔζʹϚονͨ͠ΒείΞΛϒʔετ ͍ͯ͠Δ •

    ྫ:ʮঁਆసੜʯͰݕࡧ͢ΔͱʮਅɾঁਆసੜIII NOCTURNEʯͷ΄͏͕ʮҟੈքʹঁਆͱͯ͠సੜ͠ ͨʯΑΓ΋είΞ͕ߴ͘ͳΔ
  7. Field Value Factor • ಛఆͷϑΟʔϧυͷ஋ͰείΞΛϒʔετͤ͞ Δػೳ • Kibelaͷ৔߹ɺϥΠΫ਺ͱτϥοΫόοΫ਺Λ Field Value

    Factorͱͯ͠൓ө͍ͤͯ͞Δ • ͭ·ΓʮΑ͘ϥΠΫ͞ΕΔจॻʯʮΑ͘Ϧ ϯΫ͞ΕΔจॻʯͷείΞ͕ߴ͍