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.
Fields of the
FuzzyKeywordtype do not support sorting or aggregation. If you need to sort or perform aggregation on aFuzzyKeywordfield, you can create avirtual columnof theKeywordtype for this purpose.To simulate a suffix query on a
Keywordfield, 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
Search request
request is a SearchRequest object that contains the following parameters.
|
Name |
Type |
Description |
|
tableName (required) |
String |
The name of the data table. |
|
indexName (required) |
String |
The name of the search index. |
|
searchQuery (required) |
SearchQuery |
The query condition and general query settings. |
|
columnsToGet (optional) |
SearchRequest.ColumnsToGet |
The columns to return. If this parameter is not configured, only primary key columns are returned. |
|
timeoutInMillisecond (optional) |
int |
The request-level query timeout in milliseconds. The default value is |
|
routingValues (optional) |
|
The primary key values that correspond to custom routing fields. Leave this parameter unset if custom routing is not configured. |
Query settings
request.searchQuery is a SearchQuery object that contains the following parameters.
|
Name |
Type |
Description |
|
query (required) |
Query |
The query condition. Set this parameter to a |
|
offset (optional) |
Integer |
The position from which to start the current query. |
|
limit (optional) |
Integer |
The maximum number of rows to return. Set this parameter to |
|
collapse (optional) |
Collapse |
The collapse configuration used to deduplicate results by a specified field. For more information, see Collapse (distinct). |
|
sort (optional) |
Sort |
The sort order of the results. |
|
trackTotalCount (optional) |
int |
The maximum number of matching rows to count. The default value is |
|
filter (optional) |
SearchFilter |
A post-query filter applied to the results of |
|
aggregationList (optional) |
|
The aggregation configurations. |
|
groupByList (optional) |
|
The grouping configurations. |
|
token (optional) |
byte[] |
The pagination token. Set the |
Query condition
request.searchQuery.query is a SuffixQuery object that contains the following parameters.
|
Name |
Type |
Description |
|
fieldName (required) |
String |
The name of the |
|
suffix (required) |
String |
The query string. The complete field value must end with this string. Matching is case-sensitive. |
|
weight (optional) |
float |
The relevance weight of the query condition. The value must be a positive floating-point number. A larger value gives the condition more influence on the BM25 relevance score. This parameter does not change which rows match or how many rows are returned. It affects result order only when |
Returned columns
request.columnsToGet is a SearchRequest.ColumnsToGet object that contains the following parameters.
|
Name |
Type |
Description |
|
columns (optional) |
|
The attribute columns to return. Configure this parameter only if both |
|
returnAll (optional) |
boolean |
Specifies whether to return all attribute columns from the data table. The default value is |
|
returnAllFromIndex (optional) |
boolean |
Specifies whether to return all indexed attribute columns. The default value is |
Usage
Perform a suffix query by using the Tablestore console or an SDK. Before you begin, complete the following prerequisites:
You have created a
RAM userand granted it permissions to access Tablestore. For more information, see Use the AccessKey pair of a RAM user to access Tablestore.You have created a data table. For more information, see Operations on data tables.
You have created a search index for the data table. For more information, see Create a search index.
Billing
Querying data by using a Search Index consumes read throughput. For more information, see Search Index metering and billing.
FAQ
Related topics
Search Index supports various query types for multi-dimensional data queries, including term query, terms query, match all query, match query, phrase match query, range query, prefix query, suffix query, wildcard query, token-based wildcard query, boolean query, geo query, nested query, vector search, and exists query.
When you query data, you can sort and paginate the result set or perform collapsing (deduplication).
For data analysis, such as finding the maximum or minimum value, calculating a sum, or counting rows, you can use the statistical aggregation or SQL query features.
To quickly export data regardless of the result set order, you can use the Parallel Scan feature.