本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
更新索引典
您可以在建立索引典之後變更其組態。您可以變更索引典名稱和 IAM 資訊等詳細資料。您也可以變更索引典檔案 Amazon S3 路徑的位置。如果您變更索引典檔案的路徑, Amazon Kendra
會以更新路徑中指定的索引典取代現有的索引典。
您最多可能需要 30 分鐘才能看到更新的索引典檔案的效果。
如果索引典檔案中有驗證或語法錯誤,則會保留先前上傳的索引典檔案。
下列程序顯示如何修改索引典詳細資料。
- Console
-
若要修改索引典詳細資料
-
在左側導覽窗格的索引下,選擇 [同義字]。
-
在「同義字」頁面上,選取您要修改的同義字辭典,然後選擇「編輯」。
-
在 [更新索引典] 頁面上,更新索引典詳細資料。
-
(選擇性) 選擇 [變更索引典檔案路徑],然後指定新索引典檔案的 Amazon S3 路徑。您現有的索引典檔案會由您指定的檔案取代。如果您不變更路徑,請從現有路徑 Amazon Kendra 重新載入同義字辭典。
如果您選取「保留目前的索引典檔案」,則 Amazon Kendra 不會重新載入同義字辭典檔案。
-
選擇 [儲存] 以儲存組態。
您也可以從現有的索引典路徑重新載入索引典。
從既有路徑重新載入同義字辭典
-
在左側導覽窗格的索引下,選擇 [同義字]。
-
在「同義字」頁面上,選取您要重新載入的同義字辭典,然後選擇「重新整理」。
-
在 [重新載入索引典檔案] 頁面上,確認您要重新整理索引典檔案。
- CLI
-
若要更新索引典,請呼叫:update-thesaurus
aws kendra update-thesaurus \
--index-id index-id
\
--name "thesaurus-name
" \
--description "thesaurus-description
" \
--source-s3-path "Bucket=bucket-name
,Key=thesaurus/synonyms.txt
" \
--role-arn role-arn
- Python
-
import boto3
from botocore.exceptions import ClientError
import pprint
import time
kendra = boto3.client("kendra")
print("Update a thesaurus")
thesaurus_name = "thesaurus-name
"
thesaurus_description = "thesaurus-description
"
thesaurus_role_arn = "role-arn
"
thesaurus_id = "thesaurus-id
"
index_id = "index-id
"
s3_bucket_name = "bucket-name
"
s3_key = "thesaurus-file
"
source_s3_path= {
'Bucket': s3_bucket_name,
'Key': s3_key
}
try:
kendra.update_thesaurus(
Id = thesaurus_id,
IndexId = index_id,
Description = thesaurus_description,
Name = thesaurus_name,
RoleArn = thesaurus_role_arn,
SourceS3Path = source_s3_path
)
print("Wait for Kendra to update the thesaurus.")
while True:
thesaurus_description = kendra.describe_thesaurus(
Id = thesaurus_id,
IndexId = index_id
)
status = thesaurus_description["Status"]
print("Updating thesaurus. Status: " + status)
if status != "UPDATING":
break
time.sleep(60)
except ClientError as e:
print("%s" % e)
print("Program ends.")
- Java
-
package com.amazonaws.kendra;
import software.amazon.awssdk.services.kendra.KendraClient;
import software.amazon.awssdk.services.kendra.model.UpdateThesaurusRequest;
import software.amazon.awssdk.services.kendra.model.DescribeThesaurusRequest;
import software.amazon.awssdk.services.kendra.model.DescribeThesaurusResponse;
import software.amazon.awssdk.services.kendra.model.S3Path;
import software.amazon.awssdk.services.kendra.model.ThesaurusStatus;
public class UpdateThesaurusExample {
public static void main(String[] args) throws InterruptedException {
KendraClient kendra = KendraClient.builder().build();
String thesaurusName = "thesaurus-name
";
String thesaurusDescription = "thesaurus-description
";
String thesaurusRoleArn = "role-arn
";
String s3BucketName = "bucket-name
";
String s3Key = "thesaurus-file
";
String thesaurusId = "thesaurus-id
";
String indexId = "index-id
";
UpdateThesaurusRequest updateThesaurusRequest = UpdateThesaurusRequest
.builder()
.id(thesaurusId)
.indexId(indexId)
.name(thesaurusName)
.description(thesaurusDescription)
.roleArn(thesaurusRoleArn)
.sourceS3Path(S3Path.builder()
.bucket(s3BucketName)
.key(s3Key)
.build())
.build();
kendra.updateThesaurus(updateThesaurusRequest);
System.out.println(String.format("Waiting until the thesaurus with ID %s is updated.", thesaurusId));
while (true) {
DescribeThesaurusRequest describeThesaurusRequest = DescribeThesaurusRequest.builder()
.id(thesaurusId)
.indexId(indexId)
.build();
DescribeThesaurusResponse describeThesaurusResponse = kendra.describeThesaurus(describeThesaurusRequest);
ThesaurusStatus status = describeThesaurusResponse.status();
if (status != ThesaurusStatus.UPDATING) {
break;
}
TimeUnit.SECONDS.sleep(60);
}
System.out.println("Thesaurus update is complete.");
}
}