All Products
Search
Document Center

Tablestore:Range query

Last Updated:Sep 22, 2026

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

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 TableStore.QueryType.RANGE_QUERY for range queries.

fieldName

The name of the field to query.

rangeFrom

The lower bound of the query range. Whether this value is included depends on includeLower.

rangeTo

The upper bound of the query range. Whether this value is included depends on includeUpper.

includeLower

Specifies whether to include rangeFrom in the results. true is equivalent to >=; false is equivalent to >.

includeUpper

Specifies whether to include rangeTo in the results. true is equivalent to <=; false is equivalent to <.

getTotalCount

Specifies whether to return the total number of rows that match the query. Default value: false. Setting this to true may affect query performance.

columnToGet

The columns to return. Set returnType to one of the supported values, and use returnNames to specify columns when returnType is set to RETURN_SPECIFIED.

  • If you set returnType to TableStore.ColumnReturnType.RETURN_SPECIFIED, you need to configure returnNames to specify the columns that you want to return.

  • If you set the returnType parameter to TableStore.ColumnReturnType.RETURN_ALL, all columns are returned.

  • If you set the returnType parameter to TableStore.ColumnReturnType.RETURN_ALL_FROM_INDEX, all columns in the search index are returned. .

  • If you set the returnType parameter to TableStore.ColumnReturnType.RETURN_NONE, only the primary key columns are returned.

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.