

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

# FHIR 搜尋一致性層級
<a name="searching-fhir-consistency-levels"></a>

AWS HealthLake 的搜尋索引在 SEARCH 操作`POST`的 `GET`和 最終一致性模型上運作。使用最終一致性，如果資源有待定的搜尋索引更新，搜尋結果會排除資源的 N-1 版本，直到索引更新完成為止。

 AWS HealthLake 現在包含選取一致性模型對更新資源的行為能力。開發人員可以包含「最終一致性」、上述預設行為或「強一致性」。強一致性將允許具有待定搜尋索引更新之資源的 N-1 版本資源包含在搜尋結果中。這可用於即使搜尋索引更新尚未完成，結果中仍需要所有資源的使用案例。客戶可以使用 `x-amz-fhir-history-consistency-level` 請求標頭控制此行為。

## 一致性層級
<a name="fhir-search-consistency-levels"></a>

高度的一致性  
`x-amz-fhir-history-consistency-level: strong` 設定為傳回所有相符的記錄，包括有待定搜尋索引更新的記錄。當您需要在更新後立即搜尋資源時，請使用此選項。

最終一致性  
`x-amz-fhir-history-consistency-level: eventual` 設定為僅傳回已完成搜尋索引更新的記錄。如果未指定一致性層級，則此為預設行為。

## 使用範例
<a name="fhir-search-usage"></a>

1. 更新資源時：

   ```
   POST <baseURL>/Patient
   Content-Type: application/fhir+json
   x-amz-fhir-history-consistency-level: strong
   
   {
     "resourceType": "Patient",
     "id": "123",
     "meta": {
       "profile": ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"]
     },
     "identifier": [
       {
         "system": "http://example.org/identifiers",
         "value": "123"
       }
     ],
     "active": true,
     "name": [
       {
         "family": "Smith",
         "given": ["John"]
       }
     ],
     "gender": "male",
     "birthDate": "1970-01-01"
   }
   ```

1. 後續搜尋：

   ```
   GET <baseURL>/Patient?_id=123
   ```

## 最佳實務
<a name="fhir-search-best-practices"></a>
+ 當您需要立即搜尋最近更新的資源時，請使用強大的一致性
+ 針對即時可見性不重要的一般查詢使用最終一致性
+ 考慮立即可見性和潛在效能影響之間的權衡

**注意**  
一致性層級設定會影響已更新資源在搜尋結果中出現的速度，但不會影響資源的實際儲存。  
將選用`x-amz-fhir-history-consistency-level`標頭設定為 'strong' 會使每個資源的寫入容量耗用加倍。  
此功能僅適用於已啟用版本歷史記錄的資料存放區 （在 2024 年 10 月 25 日之後建立的所有資料存放區預設為啟用）。