Range query

更新时间:
复制 MD 格式

A range query retrieves data from a table based on a specified range. For a Text type field, a match is found if any token in the field's value meets the range condition.

Interface

You can perform a range query using the Search or ParallelScan operation. The query type is RangeQuery.

Parameters

Parameter

Description

fieldName

The field to match.

from

The start position value.

When you set the range condition, use `greaterThan` to specify greater than (>) or `greaterThanOrEqual` to specify greater than or equal to (>=).

to

The end position value.

When you set the range condition, use `lessThan` to specify less than (<) or `lessThanOrEqual` to specify less than or equal to (<=).

includeLower

Specifies whether to include the `from` value in the results. The type is Boolean.

includeUpper

Specifies whether to include the `to` value in the results. The type is Boolean.

query

Set the query type to RangeQuery.

sort

Sorts the results in a specified order. For more information, see Sorting and pagination.

getTotalCount

Specifies whether to return the total number of matched rows. The default value is false, which indicates that the total number of matched rows is not returned.

Returning the total number of matched rows affects query performance.

tableName

The name of the data table.

indexName

The name of the search index.

columnsToGet

Specifies whether to return all columns. This includes the `returnAll` and `columns` settings.

`returnAll` is false by default. This means not all columns are returned. You can use `columns` to specify which columns to return. If you do not use `columns` to specify columns, only primary key columns are returned.

If you set `returnAll` to true, all columns are returned.

Usage

You can perform a range query using the console, the command line interface, or a software development kit (SDK). Before you perform a range query, make the following preparations.

Use the console

  1. Go to the Indexes tab.

    1. Log on to the Tablestore console.

    2. In the top navigation bar, select a resource group and a region.

    3. On the Overview page, click the name of the instance that you want to manage or click Manage Instance in the Actions column of the instance.

    4. On the Tables tab of the Instance Details tab, click the name of the data table or click Indexes in the Actions column of the data table.

  2. On the Indexes tab, find the search index that you want to use to query data and click Manage Data in the Actions column.

  3. In the Query Data dialog box, you can query data.

    1. By default, the system returns all attribute columns. To return specific attribute columns, turn off All Columns and specify the attribute columns that you want to return. Separate multiple attribute columns with commas (,).

      Note

      By default, the system returns all primary key columns of the data table.

    2. Select the And, Or, or Not logical operator based on your business requirements.

      If you select the And logical operator, data that meets the query conditions is returned. If you select the Or operator and specify a single query condition, data that meets the query condition is returned. If you select the Or logical operator and specify multiple query conditions, data that meets one of the query conditions is returned. If you select the Not logical operator, data that does not meet the query conditions is returned.

    3. Select an index field and click Add.

    4. Set the query type for the index field to Range Query (RangeQuery) and specify a query range.

      The query range is a left-closed right-open interval.

    5. By default, the sorting feature is disabled. If you want to sort the query results based on specific fields, turn on Sort and specify the fields based on which you want to sort the query results and the sorting order.

    6. By default, the aggregation feature is disabled. If you want to collect statistics on a specific field, turn on Collect Statistics, specify the field based on which you want to collect statistics, and then configure the information that is required to collect statistics.

  4. Click OK.

    Data that meets the query conditions is displayed in the specified order on the Indexes tab.

Use the command line interface

You can run the search command in the command line interface to query data using a search index. For more information, see Search index.

  1. Run the search command to query data from the table using the `search_index` search index. This command returns all indexed columns.

    search -n search_index --return_all_indexed
  2. Enter the query conditions as prompted by the system. The following is an example:

    {
        "Offset": -1,
        "Limit": 10,
        "Collapse": null,
        "Sort": null,
        "GetTotalCount": true,
        "Token": null,
        "Query": {
            "Name": "RangeQuery",
            "Query": {
                "FieldName": "col_long",
                "From": 1,
                "To": 100,
                "IncludeLower": true,
                "IncludeUpper": false
            }
        }
    }

Use an SDK

You can use a Java SDK, Go SDK, Python SDK, Node.js SDK, .NET SDK, or PHP SDK to perform a range query. This topic uses the Java SDK as an example.

Billing rules

useVCUmode (formerly reserved mode),usesearch CNYindex queries consumeVCUcompute resources. When you useCUmode (formerly pay-as-you-go mode),usesearch CNYindex queries consumeread throughput. For more search information, seesearch CNYindex billing.

FAQ

References