

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 更新儲存庫
<a name="index-synonyms-update"></a>

您可以在建立儲存庫之後變更儲存庫的組態。您可以變更詳細資訊，例如saurus 名稱和 IAM 資訊。您也可以變更saurus 檔案 Amazon S3 路徑的位置。如果您變更儲存庫檔案的路徑， Amazon Kendra 會將現有的儲存庫取代為更新路徑中指定的儲存庫。

最多可能需要 30 分鐘的時間，才能查看已更新的saurus 檔案的效果。

**注意**  
如果saurus 檔案中存在驗證或語法錯誤，則會保留先前上傳的saurus 檔案。

下列程序說明如何修改saurus 詳細資訊。

------
#### [ Console ]

**修改saurus 詳細資訊**

1. 在左側導覽窗格中，於您要修改的索引下，選擇**同義詞**。

1. 在**同義詞**頁面上，選取您要修改的儲存庫，然後選擇**編輯**。

1. 在**更新saurus** 頁面上，更新saurus 詳細資訊。

1. （選用） 選擇**變更預存檔案路徑**，然後指定新預存檔案的 Amazon S3 路徑。您指定的檔案會取代現有的 saurus 檔案。如果您不變更路徑， 會從現有的路徑 Amazon Kendra 重新載入預存項目。

   如果您選取**保留目前的儲存庫檔案**， Amazon Kendra 不會重新載入儲存庫檔案。

1. 選擇**儲存**以儲存組態。

您也可以從現有的儲存庫路徑重新載入儲存庫。

**從現有路徑重新載入儲存庫**

1. 在左側導覽窗格中，在您要修改的索引下，選擇**同義詞**。

1. 在**同義詞**頁面上，選取您要重新載入的儲存庫，然後選擇**重新整理**。

1. 在**重新載入saurus 檔案**頁面上，確認您要重新整理saurus 檔案。

------
#### [ 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:
        # Get thesaurus description
        thesaurus_description = kendra.describe_thesaurus(
            Id = thesaurus_id,
            IndexId = index_id
        )
        # If status is not UPDATING quit
        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));

    // a new source s3 path requires re-consumption by Kendra 
    // and so can take as long as a Create Thesaurus operation
    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.");
  }
}
```

------