

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

# 索引生命週期
<a name="indexing_search_lifecycle"></a>

您可以使用下列 API 呼叫，協助進行索引的開發生命週期。

1. 您可以使用 `[CreateIndex](https://docs.aws.amazon.com/clouddirectory/latest/APIReference/API_CreateIndex.html)` API 呼叫建立索引。您可以提供索引定義結構，來描述索引將要追蹤之連接物件上的屬性。此定義也會指出索引是否應該強制執行唯一性。結果會是新索引的物件 ID，您應該立即將之連接到階層，如同其他物件一樣。例如，這可以是專門用來保留索引的分支。

1. 您可使用 `[AttachToIndex](https://docs.aws.amazon.com/clouddirectory/latest/APIReference/API_AttachToIndex.html)` API 呼叫手動將物件連接到索引。此索引會接著在每個連接的物件上自動追蹤其所定義的屬性值。

1. 若要使用索引透過更有效率的列舉來搜尋物件，請呼叫 `[ListIndex](https://docs.aws.amazon.com/clouddirectory/latest/APIReference/API_ListIndex.html)` 並視您所需指定值的範圍。

1. 使用 `[ListAttachedIndices](https://docs.aws.amazon.com/clouddirectory/latest/APIReference/API_ListAttachedIndices.html)` API 呼叫，列舉連接到指定物件的索引。

1. 使用 `[DetachFromIndex](https://docs.aws.amazon.com/clouddirectory/latest/APIReference/API_DetachFromIndex.html)` API 呼叫，從索引中手動移除物件。

1. 一旦您分離所有物件與索引，您可以使用 `[DeleteObject](https://docs.aws.amazon.com/clouddirectory/latest/APIReference/API_DeleteObject.html)` API 呼叫刪除索引。

除了所有物件使用的空間限制以外，每個目錄中的索引數量沒有任何限制。索引及其連接會耗用空間，但類似於節點及父子連結所耗用的空間。可連接到指定物件的索引數量則有限。如需詳細資訊，請參閱 [Amazon Cloud Directory 限制](limits.md)。