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

motemote-data-science-2

kur0cky
August 01, 2020

 motemote-data-science-2

ネタですが,Rからelasticsearchを使ったり,elasticsearchの便利な機能を一部紹介しています笑

kur0cky

August 01, 2020
Tweet

More Decks by kur0cky

Other Decks in Technology

Transcript

  1. Πϯετʔϧɾىಈ w .BDͷ৔߹ brew tap elastic/tap brew install elastic/tap/elasticsearch-full brew

    install elastic/tap/kibana-full brew install elastic/tap/logstash-full brew install elastic/tap/metricbeat-full elasticsearch & kibana & w IUUQMPDBMIPTUͰ৘ใ͕ฦͬͯ͘Ε͹ىಈ੒ޭ w ,JCBOB IUUQMPDBMIPTU ͷ$POTPMFΛ࢖͏ͱ৭ʑࢼ͠΍͍͢ 13 ଞͷ04͸ɿIUUQTXXXFMBTUJDDPHVJEFFOFMBTUJDTUBDLDVSSFOUJOTUBMMJOHFMBTUJDTUBDLIUNM
  2. جຊ༻ޠ w ΠϯσοΫε w FMBTUJDTFBSDI͕ݕࡧɾղੳͷର৅ͱ͢Δσʔλͷอଘઌ w υΩϡϝϯτλΠϓ w ΠϯσοΫε಺ͷάϧʔϓ w

    υΩϡϝϯτ w FMBTUJDTFBSDI಺ʹอଘ͞Εͨσʔλ w ϑΟʔϧυ w υΩϡϝϯτʹؚ·ΕΔଐੑ 14 σʔλϕʔε ςʔϒϧ Ϩίʔυ ΧϥϜ 3%#Ͱ͍͏ͱɹɹ
  3. ؆୯ͳ࢖͍ํ w +40/ͱ3&45"1*ͰઃఆɾΠϯσΩγϯάʢ౤ೖʣɾݕࡧ͢΂ͯΛߦ͏ 15 • ݕࡧ GET index_name/_search { "query"

    : { "match" : { "comment" : "σʔτ" } } } • ΠϯσΩγϯά PUT index_name/ { "name" : "ϥʔϝϯೋ࿠", "genre" : "όʔɾμΠχϯά" } • ઃఆ PUT index_name/ { "settings" : { hogehoge }, "mappings" : { fugafuga } } ܗଶૉղੳ΍શ൒֯ͷ౷ҰͳͲ ༷ʑͳઃఆΛهड़ ౤ೖ͢Δσʔλ͕ͲͷΑ͏ͳ ϑΟʔϧυΛ΋ͪ͏Δͷ͔ɼͦͷܕ΋هड़
  4. 3͔ΒFMBTUJDTFBSDIΛୟ͘ w FMBTUJDύοέʔδ͔Βୟ͘ɽ w σʔλϑϨʔϜΛ௚઀ΠϯσΩγϯάͰ͖Δɽ w શͯΛ3Ͱ׬͍݁ͤͨ͞ʂʂ w ΫΤϦ͸ɼϦετͰॻ͍ͯKTPOMJUFͰ+40/ʹ w

    جຊͷૢ࡞ 1. conn <- connect(host="127.0.0.1", port=9200) 2. docs_bulk(conn, df, index) 3. Search(conn, index, body = <query>) 16
  5. ཁ݅ͷୡ੒ w LVSPNPKJQMVHJOʹΑΔલॲཧ w τʔΫϯԽɼશ൒֯౷ҰɼεςϛϯάɼFUD w σϑΥϧτͷείΞʢ#.ʣΛ࢖͏ w ۙ͞ʹԠͨ͡ݮਰؔ਺΋࢖͏ w

    ৯΂ϩάείΞ΋࢖͏ 20 w ೔ຊޠͷݕࡧ w ΫΤϦͱͷϚον౓ w ͋·Γา͔ͤͳ͍ w ͍͍ళʹೖΔ https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-kuromoji-analyzer.html
  6. { "query": { "function_score": { "query": { ී௨ͷΫΤϦ͸͜͜ʹॻ͘ }, "functions":

    [ { "gauss": { "latitude": { "origin": [35.6591], "scale": [0.003] } } }, { "gauss": { "longitude": { "origin": [139.7003], "scale": [0.003] } } }, { "field_value_factor": { "field": ["score"], "factor": [3], "modifier": ["log"], "missing": [1] } } ], "score_mode": ["multiply"] } }, "size": [1000], "_source": ["name", "score", "genre", "tel_number"] } GVODUJPO@TDPSFʹΑΔείΞͷ౷߹ 22 Ң౓ͷݮਰ ܦ౓ͷݮਰ ϑΟʔϧυͷ஋ ͦͷ΋ͷΛ࢖͏ ͜ΕΒͷֻ͚ࢉͰ ࠷ऴతͳείΞͱ͢Δ KTPOΈʹͯ͘͘ਃ͠༁ͳ͍Ͱ͢ɾɾɾ