TairSearch is a full-text search data structure developed in-house based on Redis modules instead of Lucene or other open source search engine software libraries. TairSearch uses query syntax that is similar to that of Elasticsearch.

Overview

Compared with Elasticsearch, TairSearch has the following advantages:
  • All data and indexes are stored in memory to ensure higher throughput and lower read/write latency.
  • Update of local indexes for documents is supported. Update operations include adding a field, updating a field, deleting a field, and auto-incrementing a field.
  • Real-time indexes are supported. Data is immediately available after it is written.

Prerequisites

The instance is a performance-enhanced instance of the ApsaraDB for Redis Enhanced Edition (Tair) that runs the minor version of 1.7.27 or later. For more information about performance-enhanced instances, see Performance-enhanced instances.
Note We recommend that you update your instance to the latest minor version for more features and higher stability. For more information, see Update the minor version. If your instance is a cluster or read/write splitting instance, we recommend that you update the proxy nodes in the instance to the latest minor version. This ensures that all commands can be run as expected. For more information about cluster and read/write splitting instances, see Cluster master-replica instances and Read/write splitting instances.

Precautions

  • The TairSearch data that you want to manage is stored on the performance-enhanced instance.
  • To reduce memory usage, we recommend that you perform the following operations:
    • When you create indexes, set index to true for document fields to specify these fields as indexed fields. For other document fields, set index to false.
    • Specify the includes and excludes properties of the _source field to filter out document fields that you do not need and save fields that you need.
  • Do not add a large number of documents to a single index. Add the documents to multiple indexes. We recommend that you keep the number of documents per index within 500 million to prevent data skew in cluster instances, balance read and write traffic, and reduce the number of large keys and hotkeys.

Supported commands

Table 1. Full-text search commands
Command Syntax Description
TFT.CREATEINDEX TFT.CREATEINDEX index mappings

Creates an index and a mapping for the index. The syntax used to create a mapping is similar to that used to create an explicit mapping in Elasticsearch. For more information, see Explicit mapping. You must create an index before you can add documents to the index.

TFT.UPDATEINDEX TFT.UPDATEINDEX index mappings

Adds a properties field to the specified index. The field that you want to add cannot have the same name as an existing one. Otherwise, the field cannot be added.

TFT.GETINDEX TFT.GETINDEX index

Obtains the mapping content of an index.

TFT.ADDDOC TFT.ADDDOC index document [WITH_ID doc_id]

Adds a document to an index. You can specify a unique ID for the document in the index by using WITH_ID doc_id. If the document ID already exists, the existing ID is overwritten. If you do not specify WITH_ID doc_id, a document ID is automatically generated. By default, WITH_ID doc_id is not specified.

TFT.MADDDOC TFT.MADDDOC index document doc_id [document1 doc_id1] ...

Adds multiple documents to an index. Each document must have a document ID that is specified by doc_id.

TFT.UPDATEDOCFIELD TFT.UPDATEDOCFIELD index doc_id document
Updates the document specified by doc_id in an index. If the fields that you want to add to the document are mapped and indexed fields, the fields must be of the same data type as those used by the mapping. If the fields that you want to add are not indexed fields, the fields can be of a random data type.
Note If the fields that you want to add to the document already exist, the document is updated. If the fields that you want to add do not exist, the fields are added. If the document does not exist, the document is automatically created. In this case, the command is equivalent to TFT.ADDDOC.
TFT.DELDOCFIELD TFT.DELDOCFIELD index doc_id field [field1 field2 ...]
Deletes the specified fields from the document specified by doc_id in an index. If the fields are indexed fields, the information in the fields is also deleted from the index.
Note If the fields do not exist, the operation cannot be performed. For example, the fields may not exist because they are filtered out by using _source.
TFT.INCRLONGDOCFIELD TFT.INCRLONGDOCFIELD index doc_id field increment
Adds an increment to the specified field in the document specified by doc_id in an index. The increment can be a positive or negative integer. The data type of the field can only be long or int.
Note If the document does not exist, the document is automatically created. In this case, the existing value of the field is 0, and the updated field value is obtained by adding the increment value to the existing field value. If the field does not exist, the operation cannot be performed. For example, the field may not exist because it is filtered out by using _source.
TFT.INCRFLOATDOCFIELD TFT.INCRFLOATDOCFIELD index doc_id field increment
Adds an increment to the specified field in the document specified by doc_id in an index. The increment can be a positive or negative floating-point number. The data type of the field can be int, long, or double.
Note If the document does not exist, the document is automatically created. In this case, the existing value of the field is 0, and the updated field value is obtained by adding the increment value to the existing field value. If the field does not exist, the operation cannot be performed. For example, the field may not exist because it is filtered out by using _source.
TFT.GETDOC TFT.GETDOC index doc_id

Obtains the content of the document specified by doc_id in an index.

TFT.EXISTS TFT.EXISTS index doc_id

Checks whether the document specified by doc_id exists in an index.

TFT.DOCNUM TFT.DOCNUM index

Obtains the number of documents in an index.

TFT.SCANDOCID TFT.SCANDOCID index cursor [MATCH *value*] [COUNT count]

Obtains the IDs of all documents in an index.

TFT.DELDOC TFT.DELDOC index doc_id [doc_id] ...

Deletes the document specified by doc_id from an index. Multiple document IDs can be specified.

TFT.DELALL TFT.DELALL index

Deletes all documents from an index but retains the index.

TFT.SEARCH TFT.SEARCH index query

Queries the documents in an index. The query syntax is similar to that of the Query Domain Specific Language (DSL) of Elasticsearch. For more information, see Query DSL.

DEL DEL key [key ...] Deletes one or more TairSearch keys.
Table 2. Auto-complete commands
Command Syntax Description
TFT.ADDSUG TFT.ADDSUG index text weight [text weight] ...

Adds one or more auto-complete texts and their weights to the specified index.

TFT.DELSUG TFT.DELSUG index text [text] ...

Deletes one or more auto-complete texts from the specified index.

TFT.SUGNUM TFT.SUGNUM index

Obtains the number of auto-complete texts in the specified index.

TFT.GETSUG TFT.GETSUG index prefix [MAX_COUNT count] [FUZZY]

Obtains the auto-complete texts that can be matched based on the specified prefix. Texts are returned in descending order of weights.

TFT.GETALLSUGS TFT.GETALLSUGS index

Obtains the full auto-complete texts in the specified index.

Note The following section describes command syntax used in this topic:
  • Uppercase keyword: the command keyword.
  • Italic: Words in italic indicate variable information that you supply.
  • [options]: optional parameters. Parameters that are not included in brackets are required.
  • AB: specifies that these parameters are mutually exclusive. Select one of two or more parameters.
  • ...: specifies to repeat the preceding content.

TFT.CREATEINDEX

Item Description
Syntax TFT.CREATEINDEX index mappings
Command description

Creates an index and a mapping for the index. The syntax used to create a mapping is similar to that used to create an explicit mapping in Elasticsearch. For more information, see Explicit mapping. You must create an index before you can add documents to the index.

Parameter
  • index: the name of the index that you want to manage.
  • mappings: the mapping content. The following syntax is supported:
    • dynamic: the mapping mode. Valid values:
      • strict: the strict mapping. Only fields that have been specified in the properties field can be mapped. Only mapped fields in a document can be written. If you do not specify the mapping mode, non-strict mapping is used.
    • enabled: specifies to forcefully check whether the field types in a document to be written are the same as those specified in the properties field. If they are not the same, the document cannot be written. Valid values: true and false. The default value is true, which indicates that a forceful check is performed. This parameter takes effect only for non-indexed fields (index set to true). For indexed fields, a forceful check is performed.
    • _source: the source of the original document. This parameter does not affect the creation of field indexes. Valid values:
      • enabled: specifies whether to store the original document. Valid values:
        • true: stores the original document. By default, enabled is set to true and all fields in the document are stored.

          You can set excludes to specify the fields that you do not want to store in the original document and includes to specify fields that you want to store. Wildcards are accepted. If a field is specified by both excludes and includes, excludes takes precedence over includes and the field is not stored in the original document. Examples:

          Example 1: "_source":{"enabled":true} specifies to store all fields and works like "_source":{"enabled":true,"excludes":[],"includes":[]}.

          Example 2: "_source":{"enabled":true,"excludes":[],"includes":["id","name"]} specifies to store only id and name fields.

        • false: does not store the original document.
    • properties: a collection of mapped fields. You can set the following properties for each field:
      • index: specifies whether to add the field to the index. Valid values: true and false. Default value: true.
      • boost: the weight of the field. Default value: 1. The parameter value must be a positive floating-point number. Tair automatically calculates the estimated relative score of each field.
      • type: the data type of the field. Valid values:
        • keyword: a string that cannot be split. The following parameter can be specified for the string:
          • ignore_above: the maximum number of characters that can be contained in the keyword string. Default value: 128. Example: "ignore_above":128.
        • text: a string that can be parsed by a tokenizer and then stored in an index. The following parameters can be specified for the string:
          • analyzer: the tokenizer that parses the text value and then stores the value in the index. 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. If you want a Chinese tokenizer, we recommend that you use jieba because it performs better than chinese. For example, "analyzer":"jieba" specifies to use the jieba tokenizer.
          • search_analyzer: the tokenizer that is used in the search. The supported tokenizer types are the same as those supported by the analyzer parameter. The default value of this parameter is the same as that of the analyzer parameter.
        • long: the long data type. You can convert a point in time into a UNIX timestamp and store the timestamp as a piece of long-typed data.
        • integer: the int data type.
        • double: the double data type.
Output
  • If the operation is successful, OK is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.CREATEINDEX idx:product '{"mappings":{"_source":{"enabled":true},"properties":{"product_id":{"type":"keyword","ignore_above":128},"product_name":{"type":"text"},"product_title":{"type":"text","analyzer":"jieba"},
"price":{"type":"double"}}}}'

# Create a product ID (product_id) of the keyword type and set the length limit of the ID to 128 characters. 
# Create a product name (product_name) of the text type. 
# Create a product title (product_title) of the text type and set analyzer to jieba. 
# Create a price (price) of the double type. 

Sample output:

OK

TFT.UPDATEINDEX

Item Description
Syntax TFT.UPDATEINDEX index mappings
Command description

Adds a properties field to the specified index. The field that you want to add cannot have the same name as an existing one. Otherwise, the field cannot be added.

Parameter
  • index: the name of the index that you want to manage.
  • mappings: the mapping content. You do not need to specify parameters such as dynamic and _source. You can specify only the properties field that you want to add. For more information about the syntax, see TFT.CREATEINDEX.
Output
  • If the operation is successful, OK is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.UPDATEINDEX idx:product '{"mappings":{"properties":{"product_group":{"type":"text","analyzer":"chinese"}}}}'

Sample output:

OK

TFT.GETINDEX

Item Description
Syntax TFT.GETINDEX index
Command description

Obtains the mapping content of an index.

Parameter
  • index: the name of the index that you want to manage.
Output
  • If the operation is successful, the JSON-typed mapping content of the index is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.GETINDEX idx:product

Sample output:

{"idx:product0310":{"mappings":{"_source":{"enabled":true,"excludes":[],"includes":["product_id"]},"dynamic":"false","properties":{"price":{"boost":1.0,"enabled":true,"ignore_above":-1,"index":true,"similarity":"classic","type":"double"},"product_id":{"boost":1.0,"enabled":true,"ignore_above":128,"index":true,"similarity":"classic","type":"keyword"},"product_name":{"boost":1.0,"enabled":true,"ignore_above":-1,"index":true,"similarity":"classic","type":"text"},"product_title":{"analyzer":"chinese","boost":1.0,"enabled":true,"ignore_above":-1,"index":true,"similarity":"classic","type":"text"}}}}}

TFT.ADDDOC

Item Description
Syntax TFT.ADDDOC index document [WITH_ID doc_id]
Command description

Adds a document to an index. You can specify a unique ID for the document in the index by using WITH_ID doc_id. If the document ID already exists, the existing ID is overwritten. If you do not specify WITH_ID doc_id, a document ID is automatically generated. By default, WITH_ID doc_id is not specified.

Parameter
  • index: the name of the index that you want to manage.
  • document: the JSON-typed document that you want to add to the index.
    Note If you use _source and includes to specify to retain only some fields, only the fields specified by includes are retained when you add a document to the index or update a document added to the index.
  • WITH_ID doc_id: specifies whether to configure the ID of the document. If yes, you must also enter a string as the doc_id value.
Output
  • If the operation is successful, the JSON-typed document ID is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.ADDDOC idx:product '{"product_id":"product test"}' WITH_ID 00001

Sample output:

"{\"_id\":\"00001\"}"

TFT.MADDDOC

Item Description
Syntax TFT.MADDDOC index document doc_id [document1 doc_id1] ...
Command description

Adds multiple documents to an index. Each document must have a document ID that is specified by doc_id.

Parameter
  • index: the name of the index that you want to manage.
  • document: the JSON-typed document that you want to add to the index.
    Note If you use _source and includes to specify to retain only some fields, only the fields specified by includes are retained when you add a document to the index or update a document added to the index.
  • doc_id: the ID of the document. The value is a string.
Output
  • If the operation is successful, OK is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.MADDDOC idx:product '{"product_id":"test1"}' 00011 '{"product_id":"test2"}' 00012

Sample output:

OK

TFT.UPDATEDOCFIELD

Item Description
Syntax TFT.UPDATEDOCFIELD index doc_id document
Command description
Updates the document specified by doc_id in an index. If the fields that you want to add to the document are mapped and indexed fields, the fields must be of the same data type as those used by the mapping. If the fields that you want to add are not indexed fields, the fields can be of a random data type.
Note If the fields that you want to add to the document already exist, the document is updated. If the fields that you want to add do not exist, the fields are added. If the document does not exist, the document is automatically created. In this case, the command is equivalent to TFT.ADDDOC.
Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
  • document: the JSON-typed content that is used to update the document.
    Note If you use _source and includes to specify to retain only some fields, only the fields specified by includes are retained when you add a document to the index or update a document added to the index.
Output
  • If the operation is successful, OK is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.UPDATEDOCFIELD idx:product 00011 '{"product_id":"test8","product_group":"BOOK"}'

Sample output:

OK

TFT.DELDOCFIELD

Item Description
Syntax TFT.DELDOCFIELD index doc_id field [field1 field2 ...]
Command description
Deletes the specified fields from the document specified by doc_id in an index. If the fields are indexed fields, the information in the fields is also deleted from the index.
Note If the fields do not exist, the operation cannot be performed. For example, the fields may not exist because they are filtered out by using _source.
Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
  • field: the field that you want to delete.
Output
  • If the operation is successful, the number of deleted fields is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.DELDOCFIELD idx:product 00011 product_group

Sample output:

(integer) 1

TFT.INCRLONGDOCFIELD

Item Description
Syntax TFT.INCRLONGDOCFIELD index doc_id field increment
Command description
Adds an increment to the specified field in the document specified by doc_id in an index. The increment can be a positive or negative integer. The data type of the field can only be long or int.
Note If the document does not exist, the document is automatically created. In this case, the existing value of the field is 0, and the updated field value is obtained by adding the increment value to the existing field value. If the field does not exist, the operation cannot be performed. For example, the field may not exist because it is filtered out by using _source.
Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
  • field: the field to which you want to add an increment. The data type of the field can only be long or int.
  • increment: the increment value that you want to add to the field. The value must be an integer. You can specify a negative integer. In this case, the updated field value is obtained by subtracting the increment value from the existing field value.
Output
  • If the operation is successful, the updated field value is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.INCRLONGDOCFIELD idx:product 00011 stock 100

Sample output:

(integer)100

TFT.INCRFLOATDOCFIELD

Item Description
Syntax TFT.INCRFLOATDOCFIELD index doc_id field increment
Command description
Adds an increment to the specified field in the document specified by doc_id in an index. The increment can be a positive or negative floating-point number. The data type of the field can be int, long, or double.
Note If the document does not exist, the document is automatically created. In this case, the existing value of the field is 0, and the updated field value is obtained by adding the increment value to the existing field value. If the field does not exist, the operation cannot be performed. For example, the field may not exist because it is filtered out by using _source.
Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
  • field: the field to which you want to add an increment. The data type of the field can be long, int, or double.
  • increment: the increment value that you want to add to the field. The value can be a positive or negative floating-point number. If the value is a negative one, the updated field value is obtained by subtracting the increment value from the existing field value.
Output
  • If the operation is successful, the updated field value is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.INCRFLOATDOCFIELD idx:product 00011 stock 299.6

Sample output:

"299.6"

TFT.GETDOC

Item Description
Syntax TFT.GETDOC index doc_id
Command description

Obtains the content of the document specified by doc_id in an index.

Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
Output
  • If the operation is successful, the ID and content of the document are returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.GETDOC idx:product 00011

Sample output:

"{\"_id\":\"00011\",\"_source\":{\"product_id\":\"test8\"}}"

TFT.EXISTS

Item Description
Syntax TFT.EXISTS index doc_id
Command description

Checks whether the document specified by doc_id exists in an index.

Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
Output
    • If the operation is successful and the document exists, a value of 1 is returned.
    • If the operation is successful and the field does not exist or if the operation is successful and the document does not exist, a value of 0 is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.EXISTS idx:product 00011

Sample output:

(integer) 1

TFT.DOCNUM

Item Description
Syntax TFT.DOCNUM index
Command description

Obtains the number of documents in an index.

Parameter
  • index: the name of the index that you want to manage.
Output
  • If the operation is successful, the number of documents in the index is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.DOCNUM idx:product

Sample output:

(integer) 3

TFT.SCANDOCID

Item Description
Syntax TFT.SCANDOCID index cursor [MATCH *value*] [COUNT count]
Command description

Obtains the IDs of all documents in an index.

Parameter
  • index: the name of the index that you want to manage.
  • cursor: the cursor used in this scan.
  • MATCH *value*: the matching pattern. value specifies the value that you use for matching. Example: MATCH *redis*.
  • COUNT count: the maximum number of items that can be scanned at a time. Default value: 100.
Output
  • If the operation is successful, an array is returned.
    • The first element of the array is the cursor used for the next scan. If the index is scanned, a value of 0 is returned.
    • The second element of the array is the IDs of the documents that are obtained in this scan.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.SCANDOCID idx:product 0 COUNT 3

Sample output:

1) "0"
2) 1) "00001"
   2) "00011"
   3) "00012"

TFT.DELDOC

Item Description
Syntax TFT.DELDOC index doc_id [doc_id] ...
Command description

Deletes the document specified by doc_id from an index. Multiple document IDs can be specified.

Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
Output
  • If the operation is successful, the number of deleted documents is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.DELDOC idx:product 00011 00014

Sample output:

"1"    # In this example, the document with an ID of 00014 does not exist. In this case, the 00011 document is deleted only and a value of 1 is returned. 

TFT.DELALL

Item Description
Syntax TFT.DELALL index
Command description

Deletes all documents from an index but retains the index.

Parameter
  • index: the name of the index that you want to manage.
  • doc_id: the ID of the document.
Output
  • If the operation is successful, OK is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.DELALL idx:product

Sample output:

OK

TFT.SEARCH

Item Description
Syntax TFT.SEARCH index query
Command description

Queries the documents in an index. The query syntax is similar to that of the Query Domain Specific Language (DSL) of Elasticsearch. For more information, see Query DSL.

Parameter
  • index: the name of the index that you want to manage.
  • query: the query statement. 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 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.
        • 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 is valid 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. The token query supports all field types. Examples: '{"query":{"term":{"f0":{"value":"redis","boost": 2.0}}}}' and '{"query":{"term":{"f0":"redis"}}}'.
      • terms: the multi-token query. Example: '{"query":{"terms":{"f0":["redis","excellent"]}}}'.
      • 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. 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. Valid values:
        • must: the must list. If bool is set to must, the query results must match all query clauses in this list.
        • must_not: the must_not list. If bool is set to must_not, the query results do not need to match all query clauses in this list.
        • should: the should list. If bool is set to should, the query results must match one query clause in this list. You can use minimum_should_match to specify the minimum number of query clauses that must be matched.
        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.
      • 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 this 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 the query syntax. Example: '{"query":{"bool":{"must":[{"match":{"f0":"v0"}},"term":{"f0":{"value":"redis","boost":2}}]}}}'.
    • sort: specifies to sort query results by a factor. 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.
    • 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. Default value: false. Valid values:
      • false: Only the top 100 documents are queried. Documents are sorted by score.
      • true: All documents are queried.
        Warning If track_total_hits is set to true and the number of documents to query is large, slow queries can be observed. Proceed with caution.
    • 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.
      Note A combination of from and size works like paging. However, query performance degrades as the number of discrete pages increases.
Output
  • If the operation is successful, the documents in the index are returned.
    Note In the following sample output, relation indicates the number of returned documents. Valid values of relation: eq (equal to the value specified by value), gte (greater than or equal to the value specified by value).
    {
        "hits": {
            "hits": [],
            "max_score": null,
            "total": {
                "relation": "gte",
                "value": 100
            }
        }
    }
  • Otherwise, an error message is returned.
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}}}'

TFT.ADDSUG

Item Description
Syntax TFT.ADDSUG index text weight [text weight] ...
Command description

Adds one or more auto-complete texts and their weights to the specified index.

Parameter
  • index: the name of the index that you want to manage.
  • text: the auto-complete text that you want to add to the index.
  • weight: the weight of the text. The weight must be a positive integer.
Output
  • If the operation is successful, the number of added texts is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.ADDSUG idx:redis 'redis is a memory database' 3 'redis cluster' 10

Sample output:

(integer) 2

TFT.DELSUG

Item Description
Syntax TFT.DELSUG index text [text] ...
Command description

Deletes one or more auto-complete texts from the specified index.

Parameter
  • index: the name of the index that you want to manage.
  • text: the text that you want to delete from the index. The text value must be complete and accurate.
Output
  • If the operation is successful, the number of deleted texts is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.DELSUG idx:redis 'redis is a memory database' 'redis cluster' 

Sample output:

(integer) 2

TFT.SUGNUM

Item Description
Syntax TFT.SUGNUM index
Command description

Obtains the number of auto-complete texts in the specified index.

Parameter
  • index: the name of the index that you want to manage.
Output
  • If the operation is successful, the number of texts in the index is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.SUGNUM idx:redis

Sample output:

(integer) 3

TFT.GETSUG

Item Description
Syntax TFT.GETSUG index prefix [MAX_COUNT count] [FUZZY]
Command description

Obtains the auto-complete texts that can be matched based on the specified prefix. Texts are returned in descending order of weights.

Parameter
  • index: the name of the index that you want to manage.
  • prefix: the prefix that you specify.
  • MAX_COUNT count: the maximum number of texts that can be returned. Valid values: 0 to 255.
  • FUZZY: specifies whether to enable fuzzy match.
Output
  • If the operation is successful, the number of texts in the index is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.GETSUG idx:redis res MAX_COUNT 2 FUZZY

Sample output:

1) "redis cluster"
2) "redis lock"

TFT.GETALLSUGS

Item Description
Syntax TFT.GETALLSUGS index
Command description

Obtains the full auto-complete texts in the specified index.

Parameter
  • index: the name of the index that you want to manage by running this command.
Output
  • If the operation is successful, a list of auto-complete texts is returned.
  • Otherwise, an error message is returned.
Example

Sample command:

TFT.GETALLSUGS idx:redis

Sample output:

1) "redis cluster"
2) "redis lock"
3) "redis is a memory database"