Retrieves rows where a field value falls within a specified range. For TEXT fields, Tablestore tokenizes the field value — a row matches when at least one token falls within the range.
Prerequisites
-
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
-
A data table is created and data is written to the data table. For more information, see Create data tables and Write data.
-
A search index is created for the data table. For more information, see Create a search index.
Examples
The following example retrieves rows where Col_Long is greater than or equal to 1 and less than 10 (1 <= Col_Long < 10), sorted by Col_Long in descending order.
client.search({
tableName: TABLE_NAME,
indexName: INDEX_NAME,
searchQuery: {
offset: 0,
limit: 10, // Set to 0 to return only the row count, not the data.
query: {
queryType: TableStore.QueryType.RANGE_QUERY,
query: {
fieldName: "Col_Long",
rangeFrom: 1,
includeLower: true, // >= rangeFrom (equivalent to >=)
rangeTo: 10,
includeUpper: false // < rangeTo (equivalent to <)
}
},
getTotalCount: true // Returns the total row count. May affect query performance.
},
columnToGet: {
// RETURN_ALL: all columns
// RETURN_SPECIFIED: columns listed in returnNames
// RETURN_ALL_FROM_INDEX: all columns in the search index
// RETURN_NONE: primary key columns only
returnType: TableStore.ColumnReturnType.RETURN_ALL
}
}, function (err, data) {
if (err) {
console.log('error:', err);
return;
}
console.log('success:', JSON.stringify(data, null, 2));
});
Parameters
|
Parameter |
Description |
|
tableName |
The name of the data table. |
|
indexName |
The name of the search index. |
|
offset |
The number of rows to skip before returning results. Default value: 0. |
|
limit |
The maximum number of rows to return. Set to 0 to return only the row count without data. |
|
queryType |
The query type. Set to |
|
fieldName |
The name of the field to query. |
|
rangeFrom |
The lower bound of the query range. Whether this value is included depends on |
|
rangeTo |
The upper bound of the query range. Whether this value is included depends on |
|
includeLower |
Specifies whether to include |
|
includeUpper |
Specifies whether to include |
|
getTotalCount |
Specifies whether to return the total number of rows that match the query. Default value: false. Setting this to |
|
columnToGet |
The columns to return. Set
|
FAQ
FAQ
References
The following query types are supported by search indexes: term query, terms query, match all query, match query, match phrase query, prefix query, range query, wildcard query, Boolean query, geo query, nested query, vector query, and exists query. You can select a query type to query data based on your business requirements.
If you want to sort or paginate the rows that meet the query conditions, you can use the sorting and paging feature. For more information, see Sorting and paging.
If you want to collapse the result set based on a specific column, you can use the collapse (distinct) feature. This way, data of the specified type appears only once in the query results. For more information, see Collapse (distinct).
If you want to analyze data in a data table, such as obtaining the extreme values, sum, and total number of rows, you can perform aggregation operations or execute SQL statements. For more information, see Aggregation and SQL query.
If you want to quickly obtain all rows that meet the query conditions without the need to sort the rows, you can call the ParallelScan and ComputeSplits operations to use the parallel scan feature. For more information, see Parallel scan.