

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

# Amazon S3 文件中繼資料
<a name="s3-metadata"></a>

您可以使用中繼資料檔案，將中繼資料、文件的其他資訊新增至 Amazon S3 儲存貯體中的文件。每個中繼資料檔案都與索引文件相關聯。

您的中繼資料檔案必須存放在與索引文件相同的 儲存貯體中。您可以在建立 Amazon S3 資料來源時，使用 主控台或 `DocumentsMetadataConfiguration` 參數的 `S3Prefix` 欄位，為中繼資料檔案指定儲存貯體內的位置。若未指定 Amazon S3 字首，中繼資料檔案必須存放在與索引文件相同的位置。

如果您為中繼資料檔案指定 Amazon S3 字首，它們位於與索引文件平行的目錄結構中。 只會在中繼資料的指定目錄中 Amazon Kendra 尋找 。如果中繼資料未被讀取，請檢查目錄位置是否與中繼資料的位置相符。

下列範例說明索引文件位置如何對應到中繼資料檔案位置。請注意，文件的 Amazon S3 金鑰會附加到中繼資料的 Amazon S3 字首，然後加上 的尾碼`.metadata.json`，以形成中繼資料檔案的 Amazon S3 路徑。包含中繼資料 Amazon S3 前綴和`.metadata.json`後綴的合併 Amazon S3 金鑰總計不得超過 1024 個字元。建議您將 Amazon S3 金鑰保持在 1000 個字元以下，以便在將金鑰與字首和字尾結合時考慮額外的字元。

```
Bucket name:
     s3://bucketName
Document path:
     documents
Metadata path:
     none
File mapping
     s3://bucketName/documents/file.txt -> 
        s3://bucketName/documents/file.txt.metadata.json
```

```
Bucket name:
     s3://bucketName
Document path:
     documents/legal
Metadata path:
     metadata
File mapping
     s3://bucketName/documents/legal/file.txt -> 
        s3://bucketName/metadata/documents/legal/file.txt.metadata.json
```

您的文件中繼資料是在 JSON 檔案中定義。檔案必須為不含 BOM 標記的 UTF-8 文字檔案。JSON 檔案的檔名必須為 `<document>.<extension>.metadata.json`。在此範例中，「文件」是中繼資料套用的文件名稱，而「延伸」是文件的副檔名。文件 ID 在 `<document>.<extension>.metadata.json` 中必須是唯一的。

JSON 檔案的內容遵循此範本。所有屬性/欄位都是選用的，因此不需要包含所有屬性。您必須為每個要包含的屬性提供一個值；該值不能為空。如果您未指定 `_source_uri`，則搜尋結果 Amazon Kendra 中 傳回的連結會指向包含文件的 Amazon S3 儲存貯體。 `DocumentId` 會對應至 欄位，`s3_document_id`且 是 S3 中文件的絕對路徑。

```
{
    "DocumentId": "{{S3 document ID, the S3 path to doc}}",
    "Attributes": {
        "_category": "{{document category}}",
        "_created_at": "{{ISO 8601 encoded string}}",
        "_last_updated_at": "{{ISO 8601 encoded string}}",
        "_source_uri": "{{document URI}}",
        "_version": "{{file version}}",
        "_view_count": {{number of times document has been viewed}},
        "custom attribute key": "custom attribute value",
        {{additional custom attributes}}
    },
    "AccessControlList": [
         {
             "Name": "{{user name}}",
             "Type": "{{GROUP}} | {{USER}}",
             "Access": "{{ALLOW}} | {{DENY}}"
         }
    ],
    "Title": "{{document title}}",
    "ContentType": "{{For example HTML}} | {{PDF}}. For supported content types, see [Types of documents](https://docs.aws.amazon.com/kendra/latest/dg/index-document-types.html)."
}
```

`_created_at` 與 `_last_updated_at` 中繼資料欄位的值均須採用 ISO 8601 日期編碼格式。例如，2012-03-25T12:30:10\+01:00 表示以 ISO 8601 格式記錄的時間：歐洲中部時間 2012 年 3 月 25 日 12:30 (加 10 秒)。

您可以新增有關用來篩選查詢或將查詢回應分組之文件的其他資訊至 `Attributes` 欄位。如需詳細資訊，請參閱[建立自訂文件欄位](custom-attributes.md)。

您可利用 `AccessControlList` 欄位篩選查詢回應。如此即可限制僅特定使用者與群組存取文件。如需詳細資訊，請參閱[篩選使用者內容](user-context-filter.md)。