

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 시작하기 자습서
<a name="location-indexing-tutorial"></a>

이 자습서에서는 [플릿 인덱싱](iot-indexing.md)을 사용하여 [위치 데이터를 인덱싱](location-indexing-geoquery.md)하는 방법을 보여줍니다. 간소화를 위해 디바이스를 나타내는 사물을 생성하고 위치 데이터를 명명된 섀도에 저장하고, 위치 인덱싱을 위한 사물 인덱싱 구성을 업데이트하고, 예시 지오쿼리를 실행하여 방사형 경계 내의 디바이스를 검색합니다.

이 자습서는 완료하는 데 약 15분이 소요됩니다.

**Topics**
+ [사전 조건](#location-indexing-tutorial-prerequisites)
+ [사물 및 섀도 생성](#location-indexing-create-resources)
+ [사물 인덱싱 구성 업데이트](#location-indexing-update-configuration)
+ [지오쿼리 실행](#location-indexing-run-geoquery)

## 사전 조건
<a name="location-indexing-tutorial-prerequisites"></a>
+ [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)의 최신 버전을 설치합니다.
+ [위치 인덱싱 및 지오쿼리](https://docs.aws.amazon.com/iot/latest/developerguide/location-indexing-geoquery.html) , [사물 인덱싱 관리](https://docs.aws.amazon.com/iot/latest/developerguide/managing-index.html) 및 [쿼리 구문](https://docs.aws.amazon.com/iot/latest/developerguide/query-syntax.html)을 숙지합니다.

## 사물 및 섀도 생성
<a name="location-indexing-create-resources"></a>

디바이스를 나타내는 사물과 위치 데이터를 저장할 명명된 섀도를 생성합니다(협정 47.61564, -122.33584).

1. 다음 명령을 실행하여 Bike-1이라는 자전거를 나타내는 사물을 생성합니다. 를 사용하여 사물을 생성하는 방법에 대한 자세한 AWS CLI내용은 *AWS CLI** 참조*의 [create-thing](https://docs.aws.amazon.com//cli/latest/reference/iot/create-thing.html)을 참조하세요.

   ```
   aws iot create-thing --thing-name "Bike-1" \
   --attribute-payload '{"attributes": {"model":"OEM-2302-12", "battery":"35", "acqDate":"06/09/23"}}'
   ```

   이 명령의 출력은 다음과 같을 수 있습니다.

   ```
   {
       "thingName": "Bike-1",
       "thingArn": "arn:aws:iot:us-east-1:123456789012:thing/Bike-1",
       "thingId": "df9cf01d-b0c8-48fe-a2e2-e16cff6b23df"
   }
   ```

1. 다음 명령을 실행하여 Bike-1의 위치 데이터를 저장할 명명된 섀도를 생성합니다(협정 47.61564, -122.33584). 를 사용하여 명명된 섀도우를 생성하는 방법에 대한 자세한 AWS CLI내용은 *AWS CLI** 참조*의 [update-thing-shadow](https://docs.aws.amazon.com//cli/latest/reference/iot-data/update-thing-shadow.html)를 참조하세요.

   ```
   aws iot-data update-thing-shadow \
   --thing-name Bike-1 \
   --shadow-name Bike1-shadow \
   --cli-binary-format raw-in-base64-out \
   --payload '{"state":{"reported":{"coordinates":{"lat": 47.6153, "lon": -122.3333}}}}' \
   "output.txt" \
   ```

   이 명령은 출력을 생성하지 않습니다. 생성한 명명된 섀도를 보려면 [list-named-shadows-for-thing](https://docs.aws.amazon.com//cli/latest/reference/iot-data/list-named-shadows-for-thing.html) CLI 명령을 실행할 수 있습니다.

   ```
   aws iot-data list-named-shadows-for-thing --thing-name Bike-1
   ```

   이 명령의 출력은 다음과 같을 수 있습니다.

   ```
   {
       "results": [
           "Bike1-shadow"
       ],
       "timestamp": 1699574309
   }
   ```

## 사물 인덱싱 구성 업데이트
<a name="location-indexing-update-configuration"></a>

위치 데이터를 인덱싱하려면 사물 인덱싱 구성을 업데이트하여 위치 데이터를 포함해야 합니다. 위치 데이터는 이 자습서의 명명된 섀도에 저장되므로 `thingIndexingMode`를 `REGISTRY`(최소 요구 사항에서)로 설정하고 `namedShadowIndexingMode`를 `ON`으로 설정하고 위치 데이터를 구성에 추가합니다. 이 예시에서는 명명된 섀도의 이름과 섀도의 위치 데이터 경로를 `filter`에 추가해야 합니다.

1. 명령을 실행하여 위치 인덱싱에 대한 인덱싱 구성을 업데이트합니다.

   ```
   aws iot update-indexing-configuration --cli-input-json '{
   "thingIndexingConfiguration": { "thingIndexingMode": "REGISTRY",
   "thingConnectivityIndexingMode": "OFF",
   "deviceDefenderIndexingMode": "OFF",
   "namedShadowIndexingMode": "ON",
   "filter": {
       "namedShadowNames": ["Bike1-shadow"],
       "geoLocations":[{
           "name":"shadow.name.Bike1-shadow.reported.coordinates"
       }]
   },
   "customFields": [
   { "name":"attributes.battery",
   "type":"Number"}] } }'
   ```

    명령은 출력을 생성하지 않습니다. 업데이트가 완료될 때까지 잠시 기다려야 할 수 있습니다. 사물 인덱스 상태를 확인하려면 [describe-index](https://docs.aws.amazon.com//cli/latest/reference/iot/describe-index.html) CLI 명령을 실행합니다. `indexStatus` 가 `ACTIVE`로 표시되면 사물 인덱싱 업데이트가 완료된 것입니다.

1. 명령을 실행하여 인덱싱 구성을 확인합니다. 이 단계는 선택 사항입니다.

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

   출력은 다음과 같습니다.

   ```
   {
       "thingIndexingConfiguration": {
           "thingIndexingMode": "REGISTRY",
           "thingConnectivityIndexingMode": "OFF",
           "deviceDefenderIndexingMode": "OFF",
           "namedShadowIndexingMode": "ON",
           "managedFields": [
               {
                   "name": "shadow.name.*.hasDelta",
                   "type": "Boolean"
               },
               {
                   "name": "registry.version",
                   "type": "Number"
               },
               {
                   "name": "registry.thingTypeName",
                   "type": "String"
               },
               {
                   "name": "registry.thingGroupNames",
                   "type": "String"
               },
               {
                   "name": "shadow.name.*.version",
                   "type": "Number"
               },
               {
                   "name": "thingName",
                   "type": "String"
               },
               {
                   "name": "thingId",
                   "type": "String"
               }
           ],
           "customFields": [
               {
                   "name": "attributes.battery",
                   "type": "Number"
               }
           ],
           "filter": {
               "namedShadowNames": [
                   "Bike1-shadow"
               ],
               "geoLocations": [
                   {
                       "name": "shadow.name.Bike1-shadow.reported.coordinates",
                       "order": "LatLon"
                   }
               ]
           }
       },
       "thingGroupIndexingConfiguration": {
           "thingGroupIndexingMode": "OFF"
       }
   }
   ```

## 지오쿼리 실행
<a name="location-indexing-run-geoquery"></a>

이제 위치 데이터를 포함하도록 사물 인덱싱 구성을 업데이트했습니다. 몇 가지 지오쿼리를 생성하고 실행하여 원하는 검색 결과를 얻을 수 있는지 확인합니다. 지오쿼리는 [쿼리 구문](query-syntax.md)을 따라야 합니다. [지오쿼리 예시](location-indexing-geoquery.md#location-indexing-geoqueries)에서 몇 가지 유용한 예제 지오쿼리를 찾을 수 있습니다.

다음 예제 명령에서는 지오쿼리 `shadow.name.Bike1-shadow.reported.coordinates:geo_distance,47.6204,-122.3491,15.5km`를 사용하여 좌표(47.6204,-122.3491)를 사용하여 중심점에서 15.5km의 반경 거리 내에 있는 디바이스를 검색합니다.

```
aws iot search-index --query-string "shadow.name.Bike1-shadow.reported.coordinates:geo_distance,47.6204,-122.3491,15.5km"
```

좌표 ‘lat’: 47.6153, ‘lon’: -122.3333에 중심점에서 15.5km 거리 내에 있는 디바이스가 있으므로 출력에서 이 디바이스(Bike-1)를 볼 수 있습니다. 출력은 다음과 같습니다.

```
{
    "things": [
        {
            "thingName": "Bike-1",
            "thingId": "df9cf01d-b0c8-48fe-a2e2-e16cff6b23df",
            "attributes": {
                "acqDate": "06/09/23",
                "battery": "35",
                "model": "OEM-2302-12"
            },
            "shadow": "{\"reported\":{\"coordinates\":{\"lat\":47.6153,\"lon\":-122.3333}},\"metadata\":{\"reported\":{\"coordinates\":{\"lat\":{\"timestamp\":1699572906},\"lon\":{\"timestamp\":1699572906}}}},\"hasDelta\":false,\"version\":1}"
        }
    ]
}
```

자세한 내용은 [위치 데이터 인덱싱](location-indexing-geoquery.md) 단원을 참조하십시오.