LoginSignup
1
1

More than 5 years have passed since last update.

【連載】Amazon CloudSearchのCLI入門編 #2 (ドキュメントの登録)

Posted at

1.概要

担当システムのAWS化に合わせて、提供している検索エンジンをCloudSearchに置き換える事になりました。
検証するために、CLI(コマンドラインインターフェイス)経由でCloudSearchを操作したので、
その手順をまとめて残したいと思います。
※ほぼ、既知の内容と思いますが、ご了承下さい。

2.前回の記事

 【連載】Amazon CloudSearchのCLI入門編 #1 (検索ドメインの作成)

3.前提条件(再掲)

クライアントは、Windows環境です。CLIのコマンドは同じなので、他のコマンドは、環境に合わせて、
適宜読みかえて下さい。あと、アクセスキーとシークレットキーを発行してCloudSearchへ接続します。
今回、準備する検索ドメインは、以下の通りとなります。

フィールド名
id literal
artist_name_li literal
album_title_li literal
artist_name_te text
album_title_te text

※ 検証内容がliteral型とtext型のscore値の確認だったため、それぞれの検索フィードを定義しました。
※ その他、使える型は、以下のURLを参考にして下さい。
  参考URL:公式:Amazon CloudSearch ドメインのインデックスフィールドの設定

4.ドキュメントの準備

検索ドメインの型定義に合わせて、inputとなるファイルを作成します。
フォーマットは、json形式かxml形式となります。今回はjson形式のフォーマットで準備しました。

[
 {"type": "add",
  "id":   "6",
  "fields": {
    "artist_name_li": "アーティスト001",
    "artist_name_te": "アーティスト001",
    "album_title_li":"君繋ぎファイブM",
    "album_title_te":"君繋ぎファイブM"
  }
 },
  {"type": "add",
  "id":   "7",
  "fields": {
    "artist_name_li": "アーティスト001",
    "artist_name_te": "アーティスト001",
    "album_title_li":"ソルファ",
    "album_title_te":"ソルファ"
  }
 }
]

 参考URL:公式:Amazon CloudSearch 用にデータを準備

5.ドキュメントの登録

以下のコマンドを実行して、ドキュメントを登録します。

aws cloudsearchdomain upload-documents^
 --endpoint-url https://search-search-score-test-yamamoto-aaaaaaaaaaaaaaaaaaaaaaaaaa.ap-northeast-1.cloudsearch.amazonaws.com^
 --content-type application/json^
 --documents input.json

{
    "status": "success",
    "adds": 2,
    "deletes": 0
}

オプション 説明
upload-documents ドキュメント登録用のコマンドとなります。
--endpoint-url 検索ドメインの接続先を指定します。
--content-type ファイルのフォーマットを指定します。
--documents 作成したファイル名を指定します。

 参考URL:公式:Amazon CloudSearch ドメインにデータをアップロード

6.最後に

次は、ドキュメントの検索を実施します。

 

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1