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

Search everything by Alexa powered by AWS

Search everything by Alexa powered by AWS

JAWS-UG Kobe 2018/11

Hidetaka Okamoto

November 16, 2018
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Programming

Transcript

  1. S e a rc h e v e r y

    t h i n g b y A l e x a p o w e re d b y A W S J A W S - U G K o b e 2 0 1 8 / 1 1
  2. H i d e t a k a O k

    a m o t o • Digitalcube Co. Ltd. • Alexa Campions • AWS Samurai 2017 in Japan
  3. h t t p s : / / b i

    t . l y / 2 B 4 B p n D
  4. · ͱ Ί A g e n d a •

    AlexaͰͷ୯ޠݕࡧ͸Amazon.SearchQuery • ElasticsearchͰݕࡧΛϒʔετ • SPARQL͸͍͍ͧ
  5. – h t t p s : / / d

    e v e l o p e r. a m a z o n . c o m / j a / d o c s / c u s t o m - s k i l l s / s l o t - t y p e - re f e re n c e . h t m l # a m a z o n s e a rc h q u e r y “Ϣʔβʔ͕࣭໰ͦ͠͏ͳ͜ͱΛߟ͑Δͱ͖͸ɺ ඪ४·ͨ͸ΧελϜͷεϩοτλΠϓΛ࢖༻ͯ͠ ΑΓ༧ଌ͠΍͍͢ϢʔβʔೖྗΛΩϟϓνϟ͠ɺ AMAZON.SearchQueryεϩοτλΠϓΛ࢖༻ͯ͠ ݕࡧΫΤϦʔΛߏ੒͢Δɺ ΑΓ༧ଌ͠ʹ͍͘ೖྗΛΩϟϓνϟ͢Δ͜ͱΛݕ౼͍ͯͩ͘͠͞ɻ”
  6. ౎ ࢢ ɾ ஍ Ҭ Λ ݕ ࡧ ͢ Δ

    Π ϯ ςϯ τ ͷ α ϯ ϓϧ { "intents": [ { "name": "SearchIntent", "slots": [ { "name": "Query", "type": "AMAZON.SearchQuery" }, { "name": "City", "type": "AMAZON.CITY" } ], "samples": [ "࠷دΓͷ{Query}Λ୳ͯ͠", "{Query}Λݟ͚ͭͯ", "{Query}Λݕࡧͯ͠", "{City}ʹ͍ͭͯৄ͘͠ڭ͑ͯ" ] } ] }
  7. A M A Z O N . S e a

    rc h Q u e r y ʹ པ Γ ͢ ͗ ͳ ͍ • ϏϧτΠϯεϩοτ͸ಛఆͷϫʔυͷೝࣝʹڧ͍ • SearchQuery͸දه༳Ε͕ى͖΍͍͢ • ۀքݻ༗ͷසग़༻ޠͳͲ͸ΧελϜεϩοτͰͳΔ΂͘Χόʔ • [ଟ෼]ϑΥʔϧόοΫ͘Β͍ͷؾ࣋ͪͰ࢖͏ͷ͕ྑͦ͞͏
  8. ί ϯ ς ϯ π ͕ ಈ త ͳ ͷ

    Ͱ ε ϩ ο τ ࡞ Ε ͳ ͍ ໰ ୊
  9. ೖ ྗ ଆ Ͱ ೉ ͠ ͚ Ε ͹ ɺ

    ݕ ࡧ ଆ Ͱ ΍ Ε ͹ ͍ ͍ ͷ Ͱ ͸ ʁ
  10. E l a s t i c s e a

    rc h h t t p s : / / w w w. e l a s t i c . c o / j p / p ro d u c t s / e l a s t i c s e a rc h
  11. W h a t ’s a b o u t

    E l a s t i c s e a rc h ? • શจݕࡧͷͨΊͷOSS • ෳࡶͳݕࡧΫΤϦͷ࣮ߦ΋ߴ଎ͰՄೳ • AWSʹϚωʔδυαʔϏε͕͋Δ
  12. A E S : A m a z o n

    E l a s t i c s e a rc h S e r v i c e h t t p s : / / a w s . a m a z o n . c o m / j p / e l a s t i c s e a rc h - s e r v i c e /
  13. W h a t ’s a b o u t

    A E S ? • ϑϧϚωδʔυܕElasticsearch • IAMϩʔϧͳͲͰͷΞΫηε੍ޚ • Kibanaͷఏڙ͋ΓɾCognito User PoolsͰϩάΠϯೝূՄೳ • t2.micro.elasticsearch͕ແྉ࿮ʢ750h/monthʣ
  14. I A M ϙ Ϧ γ ʔ ʢ S e

    r v e r l e s s F W ʣ
  15. n p m ϥ Π ϒ ϥ Ϧ ͷ ௥

    Ճ $ npm i -S elasticsearch http-aws-es
  16. C l i e n t Π ϯελ ϯε ͷ

    η ο τΞ ο ϓ const config = { hosts: [ ‘https://YOUR_DOMAIN.es.amazonaws.com' ], connectionClass: require('http-aws-es') } const AESClient = require(‘elasticsearch').Client(config)
  17. ݕ ࡧ ͷ ࣮ ߦ const query = { index:

    '*', body: { query: { term: { title: 'Hello World' } } } } const body = await AESClient.search(query)
  18. E l a s t i c s e a

    c h Ͱ Ͱ ͖ Δ ͍ Ζ Μ ͳ ݕ ࡧ
  19. σ ʔ λ ͷ શ औ ಘ const query =

    { index: '*', body: { } }
  20. t i t l e ʹ ର ͢ Δ ׬

    શ Ұ க const query = { index: '*', body: { query: { term: { title: 'Hello World' } } } }
  21. t i t l e ʹ ର ͢ Δ A

    N D ݕ ࡧ const query = { index: '*', body: { query: { match: { title: 'Hello World' } } } }
  22. t i t l e / c o n t

    e n t ʹ ର ͢ Δ A N D ݕ ࡧ const query = { index: '*', body: { query: { multi_match: { "fields": [ "title", "content"], "query": "WordCamp Tokyo", “operator": "and" } } } }
  23. t i t l e / c o n t

    e n t ʹ ର ͢ Δ ͋ ͍ · ͍ ݕ ࡧ const query = { index: '*', body: { query: { fuzzy_like_this: { fields: [“title”, “content”], like_text: 'Hello World' } } } } H e l l o w o r l d ʹ ྨ ࣅ ͢ Δ ί ϯ ςϯ π ΋ ฦ ͢
  24. Ϩε ϙ ϯε ͷ ` _ s c o re

    ` Ͱ ྨ ࣅ ੑ Λ ൑ ఆ "hits": { "total": 207, "max_score": 3.0256464, "hits": [ { "_index": "bank", "_type": "account", "_id": "590", "_score": 3.0256464,
  25. ͦ ͷ ଞ Ͱ ͖ Δ ࣄ • KibanaͰͷίϯςϯπϏδϡΞϥΠζɾ෼ੳ •

    more_like_thisΫΤϦͰͷྨࣅίϯςϯπݕࡧ • ೔࣌ͷൣғݕࡧ΍Ң౓ܦ౓͔Βͷपล৘ใݕࡧ • Elastic StackͳΒػցֶशతͳ͜ͱ΋Մೳ(Not AWS)
  26. ͜ ͜ · Ͱ ͷ ࿩ ί ϯ ς ϯ

    π Λ ࣗ ෼ Ͱ ؅ ཧ
  27. D B P e d i a - W i

    k i p e d i a Λ L O D Խ ͢ Δ P J h t t p : / / j a . d b p e d i a . o rg /
  28. W h a t ’s a b o u t

    L O D • Liked Open Data • σʔλಉ࢜ΛϦϯΫͤ͞ΔͨΊͷٕज़ • શͯͷσʔλ͕URIΛ΋ͪɺHTTP(s)ͰΞΫηεͰ͖Δ • RDFͳͲͰσʔλ͕ߏ଄Խ͞Ε͍ͯΔ
  29. W h a t ’s a b o u t

    R D F • Resource Description Framework • Ϧιʔεʢσʔλʣͷߏ଄ɾؔ܎৘ใΛఆٛ͢Δ • KVS΍ςʔϒϧͰ͸ͳ͘ɺʮओޠɾड़ޠɾ໨తޠʯͰσʔλΛఆٛ
  30. W h a t ’s a b o u t

    R D F • ৘ใɿۭͷ৭͸੨͍ • RDF: ʮhttps://example.com/ۭ https://example.com/৭ https:// example.com/੨ʯ • औಘͨ͠URL͔Βʮۭɾ৭ɾ੨ʯͷؔ࿈৘ใΛ͞ΒʹҾ͚Δ • -> σʔλಉ͕࢜URLͰϦϯΫ͍ͯ͠ΔɿLinked Open Data
  31. W h a t ’s a b o u t

    S PA R Q L • RDFͷݕࡧʹ࢖͏ΫΤϦݴޠ • SQLʹΑ͘ࣅ͍ͯΔ͕ɺWHERE͕۟SVO(ओޠड़ޠ໨తޠ)ܗࣜ • Ϛονํ๏͸WHEREͰͷ׬શҰக͔FILTERͰͷਖ਼نදݱ͘Β͍ • දه༳Ε͕ෆ҆ͳ৔߹͸ElasticsearchͳͲ΁ΠϯσοΫεͯ͠࢖͓͏
  32. ஀ ੜ ೔ ͕ 1 ݄ 1 ೔ SELECT DISTINCT

    ?s ?label ?birthYear WHERE { ?s <http://ja.dbpedia.org/property/ੜ೔> 1 ; <http://ja.dbpedia.org/property/ੜ݄> 1 ; <http://ja.dbpedia.org/property/ੜ೥> ?birthYear ; rdfs:label ?label . } ORDER BY ?birthYear
  33. D B P e d i a x A l

    e x a Λ ΍ ͬͯ Έ ͨ h t t p s : / / w w w. a m a z o n . c o . j p / H i d e t a k a - O k a m o t o - ͝ ౰ ஍ Ϛ ε ί ο τΨ Π υ / d p / B 0 7 J L P Q N 4 M /
  34. O p e n D a t a Λ ࢖

    ͬ ͨ εΩϧ ։ ൃ ͷ ஫ ҙ ఺ • ϥΠηϯεදه͸εΩϧৄࡉͱϔϧϓɾDisplayɾΧʔυʹ͍ΕΑ͏ • σʔλͷߏ଄͕ἧ͍ͬͯͳ͍͜ͱ͕͋ΔͷͰཁ஫ҙ • Wikipediaʹ͋Δ৘ใ͕͢΂ͯ͋ΔΘ͚Ͱ͸ͳ͍ • σʔλ͕ॻ͖ݴ༿ͳͷͰɺม׵ඞਢ • ਖ਼نදݱ͔SELECT͔͠ͳ͍ͷͰɺSearchQueryʹཔΓ͗͢ͳ͍ʂ
  35. n p m i - S @ h i d

    e o k a m o t o / s i m p l e - s p a rq l - c l i e n t h t t p s : / / h i d e o k a m o t o . g i t h u b . i o / s p a rq l - c l i e n t /
  36. ॻ ͖ ݴ ༿ Λ ࿩ ͠ ݴ ༿ ʹ

    ม ͑Δ ΍ ͭ h t t p s : / / a s k - u t i l s . g i t h u b . i o / a s k - j p - f o r m a t t e r /
  37. · ͱ Ί • ϏϧτΠϯɾΧελϜεϩοτ+SearchQueryͰݕࡧڧԽ • Elasticsearch / SPARQLͳͲͰΑΓڧྗͳݕࡧ͕࣮ݱՄೳ •

    ࣭໰ʹ౴͑ΔͨΊʹݕࡧΛ࢖͏ݕࡧεΩϧ • ಉ͡ΫΤϦͰ౴͑Λऔಘ͠ɺͦΕΛ໰୊ʹ͢Ε͹ΫΠζεΩϧʹ • ΈΜͳ͍ΖΜͳσʔλͰϚογϡΞοϓ͠Α͏ʂ
  38. h t t p s : / / b i

    t . l y / 2 B 4 B p n D