本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
下列程序說明如何使用 建立 Amazon Kendra 索引 AWS CLI。程序會建立資料來源、索引,並在索引上執行查詢。
建立 Amazon Kendra 索引 (CLI)
-
執行 先決條件。
-
輸入下列命令來建立索引。
aws kendra create-index \ --name cli-getting-started-index \ --description "Index for CLI getting started guide." \ --role-arn arn:aws:iam::
account id
:role/KendraRoleForGettingStartedIndex -
等待 Amazon Kendra 建立索引。使用以下命令檢查進度。當狀態欄位為 時
ACTIVE
,請繼續下一個步驟。aws kendra describe-index \ --id
index id
-
在命令提示字元中,輸入下列命令來建立資料來源。
aws kendra create-data-source \ --index-id
index id
\ --namedata source name
\ --role-arn arn:aws:iam::account id
:role/KendraRoleForGettingStartedDataSource \ --type S3 \ --configuration '{"S3Configuration":{"BucketName":"S3 bucket name
"}}'如果您使用範本結構描述連接到資料來源,請設定範本結構描述。
aws kendra create-data-source \ --index-id
index id
\ --namedata source name
\ --role-arn arn:aws:iam::account id
:role/KendraRoleForGettingStartedDataSource \ --type TEMPLATE \ --configuration '{"TemplateConfiguration":{"Template":{JSON schema
}}}' -
建立資料來源需要 Amazon Kendra 一些時間。輸入下列命令來檢查進度。當狀態為 時
ACTIVE
,請繼續下一個步驟。aws kendra describe-data-source \ --id
data source ID
\ --index-idindex ID
-
輸入下列命令來同步資料來源。
aws kendra start-data-source-sync-job \ --id
data source ID
\ --index-idindex ID
-
Amazon Kendra 會為您的資料來源編製索引。所需的時間量取決於文件數量。您可以使用下列命令檢查同步任務的狀態。當狀態為 時
ACTIVE
,請繼續下一個步驟。aws kendra describe-data-source \ --id
data source ID
\ --index-idindex ID
-
輸入下列命令進行查詢。
aws kendra query \ --index-id
index ID
\ --query-text "search term
"搜尋結果會以 JSON 格式顯示。