

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

# 管理物件群組索引
<a name="thinggroup-index"></a>

`AWS_ThingGroups` 是包含所有物件群組的索引。您可以使用此索引，根據群組名稱、描述、屬性和所有父系群組名稱搜尋群組。

## 啟用物件群組索引
<a name="enable-group-index"></a>

您可以使用 [UpdateIndexingConfiguration](https://docs.aws.amazon.com/iot/latest/apireference/API_UpdateIndexingConfiguration.html) API 中的 `thing-group-indexing-configuration` 設定，來建立 `AWS_ThingGroups` 索引並控制其組態。您可以使用 [GetIndexingConfiguration](https://docs.aws.amazon.com/iot/latest/apireference/API_GetIndexingConfiguration.html) API，擷取目前的索引組態。

若要更新物件群組索引的組態，請執行 **update-indexing-configuration** CLI 命令：

```
aws iot update-indexing-configuration --thing-group-indexing-configuration thingGroupIndexingMode=ON
```

您也能以如下命令更新物件和物件群組索引的組態：

```
aws iot update-indexing-configuration --thing-indexing-configuration thingIndexingMode=REGISTRY --thing-group-indexing-configuration thingGroupIndexingMode=ON
```

以下是 `thingGroupIndexingMode` 的有效值。

OFF  
不建立索引/刪除索引。

ON  
建立或設定 `AWS_ThingGroups` 索引。

若要擷取目前物件和物件群組索引組態，請執行 **get-indexing-configuration** CLI 命令：

```
aws iot get-indexing-configuration
```

命令的回應如下所示：

```
{
   "thingGroupIndexingConfiguration": {
        "thingGroupIndexingMode": "ON"
    }
}
```

## 描述群組索引
<a name="describe-group-index"></a>

若要擷取 **describe-index** 索引的目前狀態，請使用 `AWS_ThingGroups` CLI 命令：

```
aws iot describe-index --index-name "AWS_ThingGroups"
```

命令的回應如下所示：

```
{
   "indexStatus": "ACTIVE", 
   "indexName": "AWS_ThingGroups", 
   "schema": "THING_GROUPS"
}
```

 AWS IoT 會在您第一次編製索引時建置您的索引。若 `indexStatus` 為 `BUILDING`，您無法在該索引內進行查詢。

## 查詢物件群組索引
<a name="search-group-index"></a>

若要查詢索引中的資料，請使用 **search-index** CLI 命令：

```
aws iot search-index --index-name "AWS_ThingGroups" --query-string "thingGroupName:mythinggroup*"
```

## Authorization
<a name="query-thinggroup-auth"></a>

您可以在 AWS IoT 政策動作中將物件群組索引指定為資源 ARN，如下所示。


****  

| Action | 資源 | 
| --- | --- | 
|  `iot:SearchIndex`  |  索引 ARN (例如，`arn:aws:iot:your-aws-region:index/AWS_ThingGroups`)。  | 
|  `iot:DescribeIndex`  |  索引 ARN (例如，`arn:aws:iot:your-aws-region:index/AWS_ThingGroups`)。  | 