Tablestore search index supports wildcard, prefix, and suffix queries to address different fuzzy matching scenarios. Choose the query type that best fits your business needs.
Background information
Fuzzy queries are common in scenarios such as searching for names, phone numbers, or order numbers. In a relational database, you use the `like` syntax for this purpose. Tablestore search index provides equivalent functionality.
Query types
Search index provides three fuzzy query types based on function:
-
Wildcard query: This query is similar to the `like` syntax in traditional relational databases. It supports two wildcard characters: the asterisk (*) and the question mark (?). In the query pattern, an asterisk (*) represents any sequence of characters, and a question mark (?) represents any single character. The query pattern can start with an asterisk (*) or a question mark (?). For example, a query for
table*ematchestablestore. -
Prefix query: This query searches for data by specifying a prefix. For example, you can query for all orders that start with
H00. -
Suffix query: This query searches for data by specifying a suffix. For example, you can query for all mobile phone numbers that end with
1234.
Fuzzy queries can also be categorized by field type and implementation:
-
Keyword type: String match-based fuzzy query: Matches strings sequentially. Performance decreases as data volume grows. Supports wildcard queries and prefix queries. Case-sensitive. Maximum field length: 4 KB.
-
FuzzyKeyword type: Optimized for fuzzy queries: Faster and more stable than the Keyword type, with performance largely unaffected by data volume. Supports wildcard queries, prefix queries, and suffix queries. Case-sensitive. Maximum field length: 2 KB.
-
Text type: Tokenization mode: Uses FuzzyAnalyzer for greater flexibility, including case-sensitivity control. Only supports token-based wildcard queries in the
*ALI*pattern. Maximum field length with FuzzyAnalyzer: 1 KB.