Parameter | index: the name of the index that you want to manage by running this command. query: the Query DSL statement that is similar to the syntax used in Elasticsearch. The following fields are supported: query: the query clause. The following syntax is supported: match: the basic match query. The following parameters are supported. In scenarios that do not require document characters to be broken into individual tokens or do not require fuzzy match, we recommend that you use commands such as term and prefix to improve query efficiency. query: the documents in the index that are obtained by using the query. Note If fuzzy match is disabled by using fuzziness, documents obtained by the query are broken into individual tokens by a tokenizer specified by analyzer. You can also specify the relationship between tokens by using operator and the minimum number of tokens that need to be matched by using minimum_should_match. If fuzzy match is enabled by using fuzziness, the preceding parameters are invalid. In this case, you can specify prefix_length.
analyzer: the tokenizer used by the match statement. Valid values: standard, chinese, arabic, cjk, czech, brazilian, german, greek, persian, french, dutch, russian, and jieba. The default value is standard, which indicates an English tokenizer. To parse Chinese characters, you can use jieba. For more information, see Search analyzers. minimum_should_match: the minimum number of tokens that need to be matched. The tokenizer breaks the query statement into tokens. This parameter takes effect when fuzzy match is disabled and operator is set to OR. operator: the relationship between tokens. Valid values: AND and OR. Default value: OR. For example, '{"query":{"match":{"f0":{"query":"redis cluster","operator":"OR"}}}}' specifies that the search condition is met when "redis" or "cluster" is contained in the documents for which you want to perform a query. fuzziness: specifies whether to enable fuzzy match for the query. By default, fuzzy match is disabled. "fuzziness":1 specifies that fuzzy match is enabled. Example: '{"query":{"match":{"f0":{"query":"excelentl","fuzziness":1}}}}' . prefix_length: the number of start characters that must be retained for a fuzzy match. Default value: 0. This parameter takes effect only when fuzzy match is enabled.
term: the token query. If this parameter is specified, the query statement is not split. This query type is more efficient than the match query. This parameter supports all field types. When you perform a token query, you can set the lowercase parameter to convert the token that you want to query to lowercase. The valid values of the lowercase parameter are true and false. The default value is true. Examples: '{"query":{"term":{"f0":{"value":"redis","boost": 2.0}}}}' and '{"query":{"term":{"f0":"Redis","lowercase":"false"}}}' . If the analyzer that is used when you add a document does not convert the document to lowercase, we recommend that you set the lowercase parameter to false. Otherwise, the document may not be found. terms: the multi-token query. A maximum of 1,024 tokens are allowed in each multi-token query. When you perform a token query, you can set the lowercase parameter to convert the token that you want to query to lowercase. The valid values of the lowercase parameter are true and false. The default value is true. Example: '{"query":{"terms":{"f0":["redis","excellent"]}}}' . If the analyzer that is used when you add a document does not convert the document to lowercase, we recommend that you set the lowercase parameter to false. Otherwise, the document may not be found. range: the range query. This parameter supports all field types. Valid values: It (less than), gt (greater than), Ite (less than or equal to), and gte (greater than or equal to). Example: '{"query":{"range":{"f0":{"lt":"abcd","gt":"ab"}}}}' . wildcard: the wildcard query. Parameter value format: "wildcard":{"field to query":{"value":"query content"}} . Supported wildcards: * and ? . Example: '{"query":{"wildcard":{"f0":{"value":"*b?Se"}}}}' . prefix: the prefix query. For example, '{"query":{"prefix":{"f0":"abcd"}}' specifies to query documents whose f0 fields start with abcd . bool: the compound query. A maximum of 1,024 tokens are allowed in each compound query. Valid values: must: The query results must match all query clauses in the must list. For example, '{"query":{"bool":{"must":[{"match":{"DB":"redis"}},{"match":{"Architectures":"cluster"}}]}}}' specifies that the type of the database that you want to query is Redis and the architecture of the instance that contains the database is cluster. must_not: The query results do not match any query clauses in the must_not list. should: the should list. If bool is set to should, the query results must match one query clause in this list. You can set the minimum_should_match parameter. minimum_should_match: specifies the minimum number of query clauses that must be matched. This parameter must be used together with should. If a bool statement contains only should, minimum_should_match is set to 1 by default. If the bool statement also contains must or must_not, minimum_should_match is set to 0 by default. For example, '{"query":{"bool":{"minimum_should_match":1,"should":[{"match":{"DB":"redis"}},{"match":{"Architectures":"cluster"}}]}}}' specifies that the type of the database that you want to query is Redis or the architecture of the instance that contains the database is cluster.
Note A bool statement can have all types of query clauses nested within it, such as bool clauses. Example: TFT.SEARCH idx:product '{"query":{"bool":{"must":[{"term":{"product_name":"apple"}},{"bool":{"minimum_should_match":1,"should":[{"term":{"price":19.5}},{"term":{"product_id":"fruits_2"}}]}}]}}}' . dis_max: the compound query for best match. By default, this parameter returns documents that match one or more query clauses. If a returned document matches multiple query clauses, the dis_max query assigns the document the highest score from the matching clauses and a tie-breaking increment to the document score if tie_breaker is specified. Valid values of tie_breaker: 0 to 1. Default value: 0. After tie_breaker is specified, the document score can be calculated based on the following formula: Score from a matching clause that has the highest score + (Scores from other matching clauses × tie_breaker value). Assume that doc1 matches three query clauses whose document scores are 5, 1, and 3 and a tie_break value of 0.5 is specified. In this case, the score of doc1 can be calculated by using the following formula: Score of doc1 = 5 + [(1 + 3) × 0.5]. Example: '{"query":{"dis_max":{"queries":[{"term":{"f0":"redis"}},{"term":{"f1":"database"}},{"match":{"title":"redis memory database"}}],"tie_breaker": 0.5}}}' . constant_score: the compound query that returns a constant score. This query wraps another query and returns a constant score equal to the query boost for every document in the filter. The boost value is of the DOUBLE type, and the default boost value is 1.0. Example: '{"query":{"constant_score":{"filter":{"term":{"f0":"abc"}},"boost":1.2}}}' . match_all: the match all query. This query matches all documents and gives them all a boost value. The boost value is of the DOUBLE type, and the default boost value is 1.0. Example: '{"query":{"match_all":{"boost":2.3}}}' .
Note If you perform a compound query by using bool, dis_max, and constant_score, you can set boost values for term, terms, range, and wildcard. The default boost value is 1. You must specify the parameter to which the boost value is applied in query syntax. Example: '{"query":{"bool":{"must":[{"match":{"f0":"v0"}},"term":{"f0":{"value":"redis","boost":2}}]}}}' . sort: sorts query results by a factor. The ARRAY data type is not supported. Default value: _score. Valid values: _score: sorts query results by weight in descending order. Example: "sort":"_score" . _doc: sorts query results by document ID in ascending order. Example: "sort":"_doc" . Specified field: sorts query results by specified field in ascending order. The field must be an indexed field (index set to true) or a field that is forcefully checked (enabled set to true). The field must be of the keyword, long, integer, or double type. For example, "sort":"price" specifies to sort query results by price in ascending order.
You can also use an array to sort query results. In this case, query results are sorted by array order. You can use order to modify the default array order. Valid values of order: desc and acs. For example, '{"sort":[{"price":{"order":"desc"}},{"_doc":{"order":"desc"}}]}' specifies to sort query results by price or by document ID if the prices are the same. _source: the fields displayed in query results. You can use includes to specify fields that you want to retain and use excludes to specify fields that you do not want to retain. Wildcards are accepted. For example, "_source":{"includes":["f0"] specifies to return only the f0 fields in query results. aggs: aggregates the results of the query clause. If the field is of the ARRAY data type, only terms aggregation is supported. For more information, see Aggregations. track_total_hits: specifies whether to query all documents when you use the term, terms, or match query. In this case, compound query is supported. If you use the match query, fuzzy match is disabled. Valid values: from: the start document to return. The default value is 0, which specifies to return the first document and all subsequent documents that are queried. size: the number of documents that can be returned. Default value: 10. Valid values: 0 to 10000. A value of 0 specifies to return only the total number of obtained documents instead of specific documents. Note A combination of from and size works like paging. However, query performance degrades as the number of discrete pages increases.
|
Example | Sample command:
TFT.SEARCH idx:product '{"sort":[{"price":{"order":"desc"}}]}'
Sample output:
{"hits":{"hits":[{"_id":"fruits_3","_index":"idx:product","_score":1.0,"_source":{"product_id":"fruits_3","product_name":"orange","price":30.2,"stock":3000}},{"_id":"fruits_2","_index":"idx:product","_score":1.0,"_source":{"product_id":"fruits_2","product_name":"banana","price":24.0,"stock":2000}},{"_id":"fruits_1","_index":"idx:product","_score":1.0,"_source":{"product_id":"fruits_1","product_name":"apple","price":19.5,"stock":1000}}],"max_score":1.0,"total":{"relation":"eq","value":3}}}
|