A wildcard query (WildcardQuery) performs a fuzzy query, similar to the LIKE operator in a database.
To implement the NOT LIKE functionality, you must use a WildcardQuery together with the mustNotQueries parameter in a boolean query. For more information, see Boolean query.
Overview
A wildcard query uses special characters for pattern matching, which improves search precision and efficiency.
When you use the WildcardQuery feature, you can use a query string with wildcards to match data. This feature supports the asterisk (*) and question mark (?) wildcards. The asterisk (*) represents any sequence of characters, and the question mark (?) represents any single character. A query string can start with an asterisk (*) or a question mark (?). For example, a query for table*e can match tablestore.
The WildcardQuery is supported for fields of the Keyword and FuzzyKeyword data types.
-
Keyword: A basic string data type. The performance of fuzzy queries, such as a wildcard query, onKeywordfields is poor for large datasets and degrades as data volume grows. -
FuzzyKeyword: A data type optimized for fuzzy queries like wildcard queries. It delivers superior and stable performance that does not degrade significantly as dataset size increases.
Search Index provides three types of wildcard queries to support various fuzzy matching requirements. For more information, see the following table.
This topic describes how to perform a WildcardQuery on fields of the Keyword and FuzzyKeyword types. To learn about implementing fuzzy queries on fields of the Text type, see Wildcard query based on tokenization.
|
Type |
Query method |
Advantage |
Disadvantage |
|
Keyword |
WildcardQuery |
Compatible with Elasticsearch. |
Query performance degrades as the amount of indexed data grows. |
|
FuzzyKeyword |
WildcardQuery |
Delivers superior and stable performance that does not degrade significantly as the data size increases. |
Causes some data expansion. |
|
Text |
MatchPhraseQuery |
Supports case-insensitive matching. |
Causes some data expansion. |
Usage notes
The query term in a WildcardQuery cannot exceed 32 characters for both Keyword and FuzzyKeyword fields.
API
To perform a wildcard query, call the Search or parallel scan operation and set the query type to WildcardQuery.
Parameters
|
Parameter |
Description |
|
fieldName |
The name of the column to query. |
|
value |
The string containing wildcards, which cannot exceed 32 characters. |
|
query |
The query type. Set this parameter to |
|
getTotalCount |
Specifies whether to return the total number of matched rows. The default value is Returning the total number of matched rows can affect query performance. |
|
weight |
The query weight, a positive floating-point number used for score-based sorting in full-text search. A higher weight assigns a higher score to the column in the query results. This parameter affects the scores of the returned results but does not affect the number of returned results. |
|
tableName |
The name of the data table. |
|
indexName |
The name of the Search Index. |
|
columnsToGet |
Specifies which columns to return. It includes the returnAll and columns settings. By default, If you set |
How to use
You can perform a wildcard query using the Tablestore console, a command-line tool (CLI), or an SDK. Before you start, complete the following preparations:
Currently, a WildcardQuery on a FuzzyKeyword field is only supported via Tablestore SDKs.
Use an Alibaba Cloud account or a RAM user with the required permissions for Table Store operations. To grant permissions to a RAM user, see Grant permissions to a RAM user by using a RAM policy.
If you use an SDK or a command-line tool, create an AccessKey for your Alibaba Cloud account or RAM user if you do not have one.
You have created a data table.
A Search Index has been created for the data table.
If you use an SDK, initialize the Tablestore Client.
If you use the command-line tool, download and start the tool, then configure the connection to your instance and select the target table. For more information, see Download the command-line tool, Start the tool and configure connection information, and Data table operations.
Billing
In VCU mode (formerly reserved mode), Search Index queries consume VCU compute resources. In CU mode (formerly pay-as-you-go mode), they consume 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.