TairSearch is an in-house data structure for full-text search, and uses syntax that is similar to that of Elasticsearch. This topic describes how to use the bool query in TairSearch to implement compound queries.
Syntax
TairSearch supports the following types of clauses for the bool query:
must: specifies the elements that are required for documents to be returned. The semantics of this clause is similar to the semantics of
AND
.must_not: specifies the elements that cannot be contained in documents to be returned. The semantics of this clause is similar to the semantics of
NOT
.should: specifies the elements that are optional for documents to be returned. The semantics of this clause is similar to the semantics of
OR
. You can use the minimum_should_match parameter together with this clause to specify the minimum number of should clauses that documents to be returned must match. If a bool query contains only should clauses, this parameter is set to 1. If the bool query also contains must or must_not clauses, this parameter is set to 0.If a document matches both must and should clauses, the score of this document increases as a result of multiple hits. This affects the ranking of this document in the results.
The priority of these clauses in the bool query is must_not > must > should. Additionally, bool statements or any other statements can be nested inside a bool statement to implement compound queries. For more information about TairSearch, see Search.
Sample code
Create an index.
TFT.CREATEINDEX key '{ "mappings": { "properties": { "A": { "type": "keyword" }, "B": { "type": "keyword" }, "C": { "type": "keyword" } } } }'
Add document data.
TFT.ADDDOC key '{ "A": "a", "B": "b", "C": "c" }'
Query data.