

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 事物查询示例


使用查询语法在查询字符串中指定查询。查询将传递给 [https://docs.amazonaws.cn/iot/latest/apireference/API_SearchIndex.html](https://docs.amazonaws.cn/iot/latest/apireference/API_SearchIndex.html) API。下表列出了一些查询字符串示例。


| 查询字符串 | 结果 | 
| --- | --- | 
|  abc  |  在任何注册表、影子（经典未命名影子和命名影子）或 Device Defender 违规字段中查询“abc”。  | 
|  thingName:myThingName  |  查询名为 “myThingName” 的事物。  | 
|  thingName:my\$1  |  查询名称以“my”开头的事物。  | 
|  thingName:\$1my  |  查询名称以“my”结尾的事物。前导通配符的使用限制为每个查询 1 个查询词。包含前导通配符的查询最大查询长度为 100 个字符。  | 
|  thingName:\$1my\$1  |  查询包含子字符串“my”的事物。前导通配符的使用限制为每个查询 1 个查询词。包含前导通配符的查询最大查询长度为 100 个字符。  | 
|  thingName:ab?  |  查询名称为“ab”加另外一个字符的事物（例如：“aba”、“abb”、“abc”等）。  | 
|  thingTypeName:aa  |  查询与类型 aa 关联的事物。  | 
|  thingGroupNames:a  | 查询父事物组名称或者账单组名称为“a”的事物。 | 
|  thingGroupNames:a\$1  | 查询父事物组名称或者账单组名称与模式“a\$1”匹配的事物。 | 
|  attributes.myAttribute:75  |  查询属性名为“myAttribute”且属性值为 75 的事物。  | 
|  attributes.myAttribute:[75 TO 80]  |  查询属性名为“myAttribute”，且属性值在数字范围（75-80，含 75 和 80）之内的事物。  | 
|  attributes.myAttribute:\$175 TO 80]  |  查询属性名为“myAttribute”，且属性值在数字范围（大于 75 且小于等于 80）之内的事物。  | 
|  attributes.serialNumber:["abcd" TO "abcf"]  |  查询属性名为“serialNumber”，且属性值在字母数字字符串范围之内的事物。此查询将返回属性名为“serialNumber”，且其值为“abcd”、“abce”或“abcf”的事物。  | 
|  attributes.myAttribute:i\$1t |  查询属性名为“myAttribute”，且属性值为以“i”开头、以“t”结尾、中间有任意数量字符的事物。  | 
|  attributes.attr1:abc AND attributes.attr2<5 NOT attributes.attr3>10  |  使用布尔表达式组合术语来查询事物。此查询将返回具有下列特征的事物：属性名为“attr1”且值为“abc”；属性名为“attr2”且值小于 5；以及属性名为“attr3”且值不大于 10。  | 
|  shadow.hasDelta:true  |  查询具有增量元素的未命名影子的事物。  | 
|  NOT attributes.model:legacy  |  查询属性名为“model”且不是“legacy”的事物。  | 
|  shadow.reported.stats.battery:\$170 TO 100\$1 (v2 OR v3) NOT attributes.model:legacy  |  查询具有以下特征的事物： [\[See the AWS documentation website for more details\]](http://docs.amazonaws.cn/iot/latest/developerguide/example-queries.html)  | 
|  shadow.reported.myvalues:2  |  查询具有以下特征的事物：影子的“reported”部分中的 `myvalues` 数组包含值 2。  | 
|  shadow.reported.location:\$1 NOT shadow.desired.stats.battery:\$1  |  查询具有以下特征的事物： [\[See the AWS documentation website for more details\]](http://docs.amazonaws.cn/iot/latest/developerguide/example-queries.html)  | 
|  shadow.name.<shadowName>.hasDelta:true  |  查询具有给定名称和增量元素影子的东西。  | 
|  shadow.name.<shadowName>.desired.filament:\$1  |  查询具有给定名称和所需灯丝特性的阴影的对象。  | 
|  shadow.name.<shadowName>.reported.location:\$1  |  查询具有给定命名影子且 `location` 属性存在于命名影子的报告部分中的事物。  | 
|  connectivity.connected:true  |  查询所有连接的设备。  | 
|  connectivity.connected:false  | 查询所有断开连接的设备。 | 
|  connectivity.connected:true AND connectivity.timestamp : [1557651600000 TO 1557867600000]  | 查询所有已连接且连接时间戳 >= 1557651600000 且 <= 1557867600000 的设备。时间戳以自纪元以来的毫秒数表示。 | 
|  connectivity.connected:false AND connectivity.timestamp : [1557651600000 TO 1557867600000]  | 查询所有已断开连接且断开连接时间戳 >= 1557651600000 且 <= 1557867600000 的设备。时间戳以自纪元以来的毫秒数表示。 | 
|  connectivity.connected:true AND connectivity.timestamp > 1557651600000  | 查询所有已连接且连接时间戳 > 1557651600000 的设备。时间戳以自纪元以来的毫秒数表示。 | 
|  connectivity.connected:\$1  | 查询具有连接信息的所有设备。 | 
|  connectivity.disconnectReason:\$1  | 查询具有连接断开原因的所有设备。 | 
|  connectivity.disconnectReason:CLIENT\$1INITIATED\$1DISCONNECT  | 查询由于 CLIENT\$1INITATE\$1DISKINATE\$1DISKINTION 而断开的所有设备。 | 
|  deviceDefender.violationCount:[0 TO 100]  | 查询设备计数值在数字范围（0-100）内的 Device Defender 违规事物。 | 
|  deviceDefender.<device-SecurityProfile>.disconnectBehavior.inViolation:true  | 查询违反安全配置文件 device-SecurityProfile 中定义的行为 disconnectBehavior 的事物。请注意，inViolation:false 不是有效的查询。 | 
|  deviceDefender.<device-SecurityProfile>.disconnectBehavior.lastViolationValue.number>2  | 查询与安全配置文件设备中disconnectBehavior定义的行为相违规的事情—— SecurityProfile 上次违规事件值大于 2。 | 
|  deviceDefender.<device-SecurityProfile>.disconnectBehavior.lastViolationTime>1634227200000  |  查询SecurityProfile 与安全配置文件设备中定义的行为`disconnectBehavior`相违规的事情——最后一次违规事件是在指定的 epoch 时间之后发生的。  | 
|  shadow.name.gps-tracker.reported.coordinates:geo\$1distance,47.6204,-122.3491,15.5km | 查询距离坐标（47.6204,-122.3491）的径向距离在 15.5 千米以内的事物。此查询字符串适用于您的位置数据存储在命名影子中的情况。 | 
|  shadow.reported.coordinates:geo\$1distance,47.6204,-122.3491,15.5km | 查询距离坐标（47.6204,-122.3491）的径向距离在 15.5 千米以内的事物。此查询字符串适用于将您的位置数据存储在经典影子中的情况。 | 