You can use range query to query data that falls within a specified range. When a table contains a TEXT string, Tablestore tokenizes the string and matches any of the tokens that fall within the specified range.

Parameters

Parameter Description
fieldName The name of the field.
from The value from which the query starts.
to The value with which the query ends.
includeLow Specifies whether the query result includes the value of the from parameter. The value is of the BOOLEAN type.
includeUpper Specifies whether the query result includes the value of the to parameter. The value is of the BOOLEAN type.

Examples

/**
 * Search the table for rows where the value in Col_Long is greater than 3. Tablestore sorts these rows by Col_Long in descending order.
 * @param client
 */
private static void rangeQuery(SyncClient client) {
    SearchQuery searchQuery = new SearchQuery();
    RangeQuery rangeQuery = new RangeQuery(); // Set the query type to RangeQuery.
    rangeQuery.setFieldName("Col_Long");  // Set the name of the field that you want to match.
    rangeQuery.greaterThan(ColumnValue.fromLong(3));  // Specify the range of the values of the field. The matched values are greater than 3.
    searchQuery.setQuery(rangeQuery);

    // Sort the query results by Col_Long in descending order.
    FieldSort fieldSort = new FieldSort("Col_Long");
    fieldSort.setOrder(SortOrder.DESC);
    searchQuery.setSort(new Sort(Arrays.asList((Sort.Sorter)fieldSort)));

    SearchRequest searchRequest = new SearchRequest(TABLE_NAME, INDEX_NAME, searchQuery);

    SearchResponse resp = client.search(searchRequest);
    System.out.println("TotalCount: " + resp.getTotalCount()); // Display the total number of matched rows instead of the number of returned rows.
    System.out.println("Row: " + resp.getRows());

    /**
     * You can set SearchAfter to start a new query. For example, you can set SearchAfter to 5 and sort the results by Col_Long in descending order. Then, you retrieve the rows that follow the row whose Col_Long value is equal to 5. In other words, rows whose Col_Long values that are smaller than 5 are returned.
     */
    searchQuery.setSearchAfter(new SearchAfter(Arrays.asList(ColumnValue.fromLong(5))));
    searchRequest = new SearchRequest(TABLE_NAME, INDEX_NAME, searchQuery);
    resp = client.search(searchRequest);
    System.out.println("TotalCount: " + resp.getTotalCount()); // Display the total number of matched rows instead of the number of returned rows.
    System.out.println("Row: " + resp.getRows());    
}