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

Let_s_Go_Talk__6__GoのLT会_.pdf

 Let_s_Go_Talk__6__GoのLT会_.pdf

Let's Go Talk #6 (GoのLT会)の発表資料になります。
https://connehito.connpass.com/event/270615/

虎の穴ラボ株式会社

January 19, 2023
Tweet

More Decks by 虎の穴ラボ株式会社

Other Decks in Technology

Transcript

  1. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    GoからOpenSearchServiceを
    使ってみる
    虎の穴ラボ株式会社 浜田拓実
    (sheltie)
    2023
    Let's Go Talk #6 (GoのLT会)

    View Slide

  2. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    自己紹介

    浜田 拓実(ハマダ タクミ)



    ● 2022/06 入社

    ● 虎の穴ラボ 通販チーム エンジニア 

    Goを始めたきっかけ

    ● 社内勉強会でGoが取り上げられた 

    ● 昨年末よりGoでWebアプリを作り始める 


    View Slide

  3. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    アジェンダ

    ● 作成物の概要

    ● OpenSearchについて

    ● ドキュメントの登録

    ● ドキュメントの検索

    ● 注意点

    ● まとめ


    View Slide

  4. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    作成物の概要

    ・楽天APIから商品情報を日次で取得

    ・取得データをOpenSearchに登録

    ・キーワードでOpenSearchを検索

    GoとOpenSearchの練習のため作成


    View Slide

  5. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    OpenSearchについて

    View Slide

  6. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    OpenSearchについて

    OpenSearchとは・・・

    ● ElasticSearchをフォークして

    開発が行われている

    ● データ検索、分析、可視化が可能。

    ● 100%オープンソース


    View Slide

  7. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    OpenSearchについて

    Goから利用する

    ● 公式から環境構築のDockerサンプルが

    提供されている

    ● Go クライアントが提供されている


    View Slide

  8. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    OpenSearchについて

    Dockerサンプル


    View Slide

  9. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    Goから利用する
    (ドキュメントの登録)

    View Slide

  10. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    ドキュメントの登録

    公式サンプルを利用する

    ● Goクライアントを利用した実装例

    ● CRUD操作を一通り実施


    View Slide

  11. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    ドキュメントの登録

    APIはJSON形式でやりとり

    ● APIのパラメータに適した

    構造体の定義

    ● json.Marshal / Unmarshalを利用

    ● JSON-to-GoでJSONを構造体に変換

    
 https://mholt.github.io/json-to-go/


    View Slide

  12. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    ドキュメントの登録

    実際の実装内容


    View Slide

  13. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    Goから利用する
    (ドキュメントの検索)

    View Slide

  14. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    ドキュメントの検索

    公式サンプルを利用する

    ● こちらもJSON形式でやりとり

    ● 独特な検索クエリに慣れる必要あり


    View Slide

  15. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    ドキュメントの検索

    実際の実装内容(前半)


    View Slide

  16. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    ドキュメントの検索

    実際の実装内容(後半)


    View Slide

  17. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    注意点

    View Slide

  18. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    注意点

    大量のドキュメントをループで登録中、以下のようなエラーが発生

    View Slide

  19. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    注意点

    公式サンプルとの相違点

    ● 更新サンプルはレスポンスを

    閉じる処理が省略されている

    ● Go Packagesのサンプルでは

    レスポンスを閉じる処理有り

    レスポンスを閉じないと、

    先ほどのエラーが発生するため注意

    View Slide

  20. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    まとめ

    View Slide

  21. Copyright (C) 2020 Toranoana Inc. All Rights Reserved.
    まとめ

    GoからOpenSearchを取り扱うのは比較的簡単

    ・OpenSearch、Go共にサンプルが充実

    ・Goクライアントが用意されている

    ・GoとJSONの相性が良い(気がする)

    OpenSearchはGoと相性の良い

    検索エンジンだと感じました


    View Slide