Advanced search
Use SQL-like statements to search for devices that meet specific criteria, such as online devices, and download a list of matching devices that includes their ProductKey and DeviceName.
Limitations
-
Supported regions: China (Shanghai), China (Beijing), China (Shenzhen).
-
Feature limitations:
-
Legacy public instances: You cannot search for devices or download device files by using Thing Specification Language (TSL) models.
-
Enterprise Edition instances and new public instances: In the China (Shanghai) region, searching for devices by TSL model is available only on the Advanced Search tab of the page.
To search by TSL model, you must first configure a TSL index. IoT Platform then uses device runtime data to retrieve the most recently reported property values and find devices that meet the specified conditions.
Important-
For each Enterprise Edition instance, you can configure indexes for a maximum of 100 TSL model properties.
-
The advanced search feature is not supported for MQTT Enterprise Edition instances.
-
-
Use cases
You can use advanced search in the following scenarios in the IoT Platform console:
-
View device information: On the Advanced Search tab of the page, search for and manage specific devices.
-
Device grouping: When adding devices to a device group, search for the devices to add.
-
Over-the-air (OTA) updates: When you verify an OTA update package or create a batch update, search for the devices to update.
You can also call the QueryDeviceBySQL API operation to perform an advanced search. The API is not limited to these console scenarios.
Procedure
The following examples show how to use advanced search in the IoT Platform console to add devices to a device group and to search for devices by TSL model.
Log on to the IoT Platform console.
On the Overview page, find the instance that you want to manage and click the instance ID or instance name.
-
search for devices that meet your criteria.
-
In the navigation pane on the left, choose . On the Groups page, find the group that you created and click View in the Actions column.
-
On the Group Details page, click the . In the Add Device to Group panel, turn on the Advanced Search switch in the upper-right corner.
-
Enter a query in the search box and click the search icon
.For more information about the query syntax, see SQL-like syntax.
The search results are displayed in a list, and a download icon appears to the right of the search box.
You can click the download icon
to download a CSV file that contains a list of the matching devices.
-
-
Search for devices by TSL model.
-
In the navigation pane on the left, choose , and then click the Advanced Search tab.
-
On the Advanced Search tab, click Configure Index next to Search by TSL model data.
-
In the TSL Index Configuration panel, select a product, a TSL model module, and the properties to index, then click OK.
Note-
After you configure property indexes, they take effect within one minute.
-
After you configure a property index, you can still search for devices based on the last reported value for that property, even if you delete the TSL model property from the product.
In the TSL Index Configuration dialog box, select the Temperature and Humidity Sensor product from the drop-down list on the left and the Default module from the drop-down list on the right. In the property list, select the Humidity (identifier:
Humidity) and Temperature (identifier:Temperature) properties. -
-
Enter a TSL index condition in the search box and click Search.
Under Search by TSL model data, you can copy property.floatText > 11 or property.module.floatText > 11. Replace floatText with the identifier of the indexed property, replace module with the identifier of the custom module, and replace 11 with the value for your search condition.
ImportantThe data type of the condition value must match the data type of the TSL model property.
For example, the TSL model property Temperature is of the Double type. To find devices that reported a temperature greater than 11, you must use the value 11.0 in your query. Otherwise, the search will fail.
The search results are displayed on the Advanced Search tab. If any devices meet the criteria, you can click Download Search Result to download a CSV file of the matching devices.
-
Optional: To remove a property's index, click Reset on the Advanced Search tab to return to the search page. Then, click Configure Index to open the TSL Index Configuration panel.
You can select a product and a TSL model module, or click Selected in the upper-right corner. Then, deselect the target property and click OK.
If a property has been deleted from a product, you can find the property in the Selected list to un-index it.
ImportantIf you remove a property's index, you can no longer search for devices based on that property.
When you remove a property index, the property's historical search data is cleared. If a large amount of historical data exists, the clearing process may take some time, and the index status is not immediately updated. If you reopen the TSL Index Configuration panel, the property may still appear as selected. Wait for the process to complete and do not repeat the operation.
-
SQL-like syntax
When you use advanced search in the console, an SQL-like statement consists of a WHERE clause and an optional ORDER BY clause. The SELECT and LIMIT clauses, and the WHERE keyword itself, are omitted. Statements are limited to 400 characters.
Example:
product_key = "a1*****" order by active_time
WHERE clause
Format:
[condition1] AND [condition2]
Omit WHERE.
You can specify a maximum of five conditions. Nested conditions are not supported.
The AND and OR logical operators are supported. You can use a maximum of five logical operators per statement.
ORDER BY clause (optional)
Use the ORDER BY clause to sort results. You can sort by the gmt_create, gmt_modified, and active_time fields.
This clause is optional. If omitted, results are returned in a random order.
Searchable fields
|
Field |
Type |
Description |
|
product_key |
text |
The ProductKey of the product to which the device belongs. |
|
iot_id |
text |
The device identifier. The iot_id field is returned by default. |
|
name |
text |
The DeviceName of the device. |
|
active_time |
date |
The time when the device was activated. The time is in the |
|
nickname |
text |
The alias of the device. |
|
gmt_create |
date |
The time when the device was created. The time is in the |
|
gmt_modified |
date |
The time when the device's nickname was last updated. The time is in the |
|
status |
text |
The status of the device. Valid values:
|
|
property.floatText |
text |
The identifier of a TSL model property.
You can search by these fields only on the Advanced Search tab of the page for an Enterprise Edition instance. |
|
property.module.floatText |
text |
|
|
group.group_id |
text |
The ID of the device group. |
|
tag.tag_name |
text |
The tag key. |
|
tag.tag_value |
text |
The tag value. |
|
ota_module.name |
text |
The name of the OTA module. Use this field with ota_module.version to specify the OTA module that corresponds to the device's current OTA version. |
|
ota_module.version |
text |
The current OTA version of the device. Use this field with ota_module.name. |
Operators
|
Operator |
Supported field types |
|
= |
number, date, text, keyword |
|
> |
number, date |
|
< |
number, date |
|
LIKE |
text |
The LIKE operator supports prefix matching but does not support suffix or wildcard matching. The prefix must meet the following conditions:
-
The prefix must contain at least four characters and cannot contain any special characters, such as backslashes (\), forward slashes (/), ampersands (&), plus signs (+), hyphens (-), exclamation points (!), parentheses (), colons (:), tildes (~), square brackets ([]), curly brackets ({}), asterisks (*), and question marks (?).
-
The prefix must end with
%.
Example:
product_key = "a1*********" and name LIKE "test%"
Related API
QueryDeviceBySQL: searches for devices that meet specified conditions by using SQL-like statements.