LoginSignup
1
2

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-02-19

1.概要

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

2.前提条件

クライアントは、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 ドメインのインデックスフィールドの設定

3.事前準備

以下のコマンド実行して、アクセスキーとシークレットキーを登録します。

set AWS_DEFAULT_REGION=ap-northeast-1
set AWS_ACCESS_KEY_ID=AKGXXXXXXXXXXXXXXXXX
set AWS_SECRET_ACCESS_KEY=0boYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

aws iam list-account-aliases ★アカウント名を確認する。

{
    "AccountAliases": [
        "rc-aws-learn-system-arch"
    ]
}

4.検索ドメインの作成

手順としては、以下の通りとなります。
① 検索ドメインの作成
② 検索フィールドの定義
③ インデックシング

まずは、検索ドメインを作成します。

aws cloudsearch create-domain --domain-name search-score-test

{
    "DomainStatus": {
        "DomainId": "540941733278/search-score-test",
        "Created": true,
        "Deleted": false,
        "SearchInstanceCount": 0,
        "DomainName": "search-score-test",
        "SearchService": {},
        "RequiresIndexDocuments": false,
        "Processing": false,
        "DocService": {},
        "ARN": "arn:aws:cloudsearch:ap-northeast-1:000000000000:domain/search-score-test",
        "SearchPartitionCount": 0
    }
}

※ 参考URL:公式:Amazon CloudSearch ドメインの作成

続いて、検索フィールドを定義します。

aws cloudsearch define-index-field^
 --domain-name search-score-test^
 --name id^
 --type literal^
 --search-enabled true^
 --return-enabled true^
 --facet-enabled false^
 --sort-enabled true^

{
    "IndexField": {
        "Status": {
            "PendingDeletion": false,
            "State": "RequiresIndexDocuments",
            "CreationDate": "2017-02-07T01:55:00.890Z",
            "UpdateVersion": 9,
            "UpdateDate": "2017-02-07T01:55:00.890Z"
        },
        "Options": {
            "LiteralOptions": {
                "FacetEnabled": false,
                "SortEnabled": true,
                "SearchEnabled": true,
                "ReturnEnabled": true
            },
            "IndexFieldType": "literal",
            "IndexFieldName": "id"
        }
    }
}


aws cloudsearch define-index-field 
 --domain-name search-score-test^
 --name artist_name_te~
 --type text^
 --return-enabled true^
 --sort-enabled true^
 --highlight-enabled false^
 --analysis-scheme _mul_default_

{
    "IndexField": {
        "Status": {
            "PendingDeletion": false,
            "State": "RequiresIndexDocuments",
            "CreationDate": "2017-02-07T01:57:00.890Z",
            "UpdateVersion": 28,
            "UpdateDate": "2017-02-07T01:57:00.890Z"
        },
        "Options": {
            "TextOptions": {
                "SortEnabled": true,
                "HighlightEnabled": false,
                "ReturnEnabled": true,
                "AnalysisScheme": "_mul_default_"
            },
            "IndexFieldType": "text",
            "IndexFieldName": "artist_name_te"
        }
    }
}

※ --nameパラメタを変更して他の検索フィードも定義する。
※ 参考URL:公式:Amazon CloudSearch ドメインのインデックスフィールドの設定

検索ドメインの定義変更を実施した場合、インインデックシングをする必要があります。
実施するまでドキュメントの登録や検索が出来ないので、インデクシングを実施します。

aws cloudsearch index-documents --domain-name search-score-test
{
    "FieldNames": [
        "album_title_li",
        "artist_name_li",
        "album_title_te",
        "artist_name_te"
    ]
}

aws cloudsearch describe-index-fields --domain-name search-score-test
{
    "IndexFields": [
        {
            "Status": {
                "PendingDeletion": false,
                "State": "Active", ★完了するとActiveとなる。
                "CreationDate": "2017-02-12T16:42:00.102Z",
                "UpdateVersion": 25,
                "UpdateDate": "2017-02-12T17:18:48.210Z"
            },
            "Options": {
                "LiteralOptions": {
                    "FacetEnabled": false,
                    "SortEnabled": true,
                    "SearchEnabled": true,
                    "ReturnEnabled": true
                },
                "IndexFieldType": "literal",
                "IndexFieldName": "album_title_li"
            }
        },
        {
            "Status": {
                "PendingDeletion": false,
                "State": "PROCESSING", ★インデクシング中はPROCESSINGとなる。
                "CreationDate": "2017-02-19T07:54:44.172Z",
                "UpdateVersion": 29,
                "UpdateDate": "2017-02-19T07:54:44.172Z"
            },
            "Options": {
                "TextOptions": {
                    "SortEnabled": true,
                    "HighlightEnabled": false,
                    "ReturnEnabled": true,
                    "AnalysisScheme": "_mul_default_"
                },
                "IndexFieldType": "text",
                "IndexFieldName": "album_title_te"
            }
        },
                <中略>
                "IndexFieldName": "artist_name_li"
            }
        },
        {
                <中略>
                "IndexFieldName": "artist_name_te"
            }
        },
        {
                <中略>
                "IndexFieldName": "id"
            }
        }
    ]
}

5.最後に

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

6.参考URL

公式:CLIドキュメント

1
2
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
2