The search indexes of Tablestore support the wildcard query, prefix query, and suffix query features to meet your fuzzy query requirements in different scenarios. You can select an appropriate query method based on your business requirements. This topic describes the types of fuzzy queries that are supported by search indexes.
Background information
During business development, you may often use the fuzzy query feature to query data such as names, phone numbers, and order numbers. In relational databases, you can use the LIKE operator to perform fuzzy queries. The search indexes of Tablestore also support the fuzzy query feature.
Query types
The search indexes of Tablestore support the following types of fuzzy query features:
Wildcard query: This feature is similar to the LIKE operator in traditional relational databases. You can specify a string that contains asterisks (*) and question marks (?) to perform wildcard queries. An asterisk (*) matches a string of any length. A question mark (?) matches a single character. The string that you specify can start with an asterisk (*) or a question mark (?). For example, if you search for the
table*e
string,tablestore
can be matched.Prefix query: You can specify a prefix to query data that matches the specified prefix. For example, you can query orders whose order numbers start with
H00
.Suffix query: You can specify a suffix to query data that matches the specified suffix. For example, you can query mobile numbers that end with
1234
.
The fuzzy query feature can be implemented in different ways based on the following field types:
Keyword: You can perform string-based fuzzy queries on fields of the Keyword type. During a query, strings are matched one by one. The query performance decreases as the amount of data increases. The Keyword type supports wildcard query and prefix query. The Keyword type is case-sensitive during queries and supports the maximum field length of 4 KB.
FuzzyKeyword: You can perform optimized fuzzy queries on fields of the FuzzyKeyword type. Compared with the Keyword type, the FuzzyKeyword type can be used to query data in a more efficient manner and deliver more stable query performance, without being affected by the amount of data. The FuzzyKeyword type supports wildcard query, prefix query, and suffix query. The FuzzyKeyword type is case-sensitive during queries and supports the maximum field length of 2 KB.
NoteThe FuzzyKeyword type is in invitational preview. If you want to use the FuzzyKeyword type, submit a ticket.
Text: You can use tokenization methods such as FuzzyAnalyzer to perform fuzzy queries on fields of the Text type in a more flexible and controllable manner. You can specify the case sensitivity of the Text type. The Text type supports tokenization-based wildcard query that searches for a string in the
*ALI*
format. When FuzzyAnalyzer is used, the Text type supports the maximum field length of 1 KB.