All Products
Search
Document Center

Tablestore:Suffix query

Last Updated:Jun 22, 2026

A suffix query (SuffixQuery) finds data in a search index that ends with a specific string. For example, you can look up a package delivery by using the last four digits of a phone number.

How it works

To run a SuffixQuery, specify the suffix value to match.

Only the FuzzyKeyword data type supports suffix queries. FuzzyKeyword is optimized for fuzzy search operations such as SuffixQuery, PrefixQuery, and wildcard query, and delivers stable performance regardless of data volume.

Note
  • Fields of the FuzzyKeyword type do not support sorting or aggregation. If you need to sort or perform aggregation on a FuzzyKeyword field, you can create a virtual column of the Keyword type for this purpose.

  • To simulate a suffix query on a Keyword field, reverse the string when writing data and then use a prefix query (PrefixQuery) to search for the data.

API

Call the Search or ParallelScan operation with the query type set to SuffixQuery.

Parameters

Parameter

Description

query

Set the query type to SuffixQuery.

fieldName

The field to match.

suffix

The suffix value.

getTotalCount

Specifies whether to return the total number of matched rows. The default value is false.

Returning the total number of matched rows affects query performance.

weight

The query weight. This parameter is used for score-based sorting in full-text index scenarios. A higher weight value results in a higher score for the matched rows. The value must be a positive floating-point number.

This parameter affects only the scores of the returned results, not the number of results.

tableName

The name of the data table.

indexName

The name of the search index.

columnsToGet

The columns to return. This includes the returnAll and columns settings.

By default, returnAll is false. If returnAll is false, you can use columns to specify the columns to return. If you do not specify columns, only the primary key columns are returned.

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

Usage

Perform a suffix query by using the Tablestore console or an SDK. Before you begin, complete the following prerequisites:

Use the Tablestore console

  1. Go to the Index Management tab.

    1. Log on to the Table Store console.

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

    3. On the Overview page, click the instance name or click Instance Management in the Actions column.

    4. On the Instance Details tab, in the Data Table List tab, click the data table name or click Index Management in the Actions column.

  2. On the Indexes tab, find the target search index and click Manage Data in the Actions column.

    1. By default, all columns are returned. To return specific columns, turn off Retrieve All Columns and enter the column names, separated by commas.

      Note

      By default, Table Store returns the primary key columns of the data table.

    2. Select a logical operator: And, Or, or Not.

      If you select And, the query returns data that meets all specified conditions. If you select Or, the query returns data that meets at least one of the specified conditions. If you select Not, the query returns data that does not meet the specified conditions.

    3. Select an index field of the FuzzyKeyword type and click Add.

    4. Set the query type for the index field to Suffix query (SuffixQuery) and enter the suffix value.

    5. By default, sorting is disabled. To sort the results by a specific field, turn on Enable Sorting, add the sort field, and configure the sort order.

    6. By default, aggregation is disabled. To perform statistical aggregation on a specific field, turn on Enable Aggregation, add the field for aggregation, and configure the aggregation settings.

  3. Click OK.

    The query results are displayed on the Index Management tab.

Use an SDK

The following example uses the Tablestore SDK for Java.

Important
  • The suffix query feature is supported in Tablestore SDK for Java 5.17.0 and later.

  • Before you perform a suffix query using the SDK, you must initialize a client. For more information, see Initialize a Tablestore client.

The following example shows how to query for data where the value in the Col_FuzzyKeyword column ends with "hangzhou".

/**
 * Query for data where the value in the Col_FuzzyKeyword column ends with "hangzhou".
 * @param client
 */
private static void suffixQuery(SyncClient client) {
    SearchQuery searchQuery = new SearchQuery();
    SuffixQuery suffixQuery = new SuffixQuery(); // Set the query type to SuffixQuery.
    searchQuery.setGetTotalCount(true);
    suffixQuery.setFieldName("Col_FuzzyKeyword");
    suffixQuery.setSuffix("hangzhou");
    searchQuery.setQuery(suffixQuery);
    //searchQuery.setGetTotalCount(true); // Set this to true to return the total number of matched rows.

    SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
    // Specify the columns to return by setting the columnsToGet parameter. If you do not set this parameter, only primary key columns are returned by default.
    SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
    //columnsToGet.setReturnAll(true); // Set this to true to return all columns.
    columnsToGet.setColumns(Arrays.asList("Col_FuzzyKeyword")); // Set this to return specified columns.
    searchRequest.setColumnsToGet(columnsToGet);

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

Billing

Querying data by using a Search Index consumes read throughput. For more information, see Search Index metering and billing.

FAQ

Related topics