You can call the BoolQuery operation to query data based on a combination of filtering conditions. A query contains one or more subqueries as filtering conditions. Table Store returns the rows that match the subqueries.

You can combine these subqueries in different ways. If you specify these subqueries as mustQueries, Table Store returns the result that meets all filtering conditions. If you specify these subqueries as mustNotQueries, Table Store returns the result that meets none of these subqueries.

# k > 'key100' and (l > 110 and l < 200) and not (k = 'key121')
# and should_queries(k > 'key120' or l < 300, minimum_should_match=2)
bool_query = BoolQuery(
    must_queries=[
        RangeQuery('k', range_from='key100', include_lower=False),
        // Set the BoolQuery.
        BoolQuery(
            // Set subqueries to obtain data that meets all filtering conditions.
            must_queries=[
                RangeQuery('l', range_from=110, include_lower=False),
                RangeQuery('l', range_to=200, include_upper=False)
            ],
        )
    ],
    // Set subqueries to exclude data that meets all filtering conditions.
    must_not_queries=[
        TermQuery('k', 'key121')
    ],
    should_queries=[
        RangeQuery('k', range_from='key120', include_lower=False),
        RangeQuery('l', range_to=300, include_upper=130)
    ],
    minimum_should_match=2
)

// Construct a query by specifying query parameters, including sorter, limit, and get_total_count.
rows, next_token, total_count, is_all_succeed = client.search(
    table_name, index_name, 
    SearchQuery(
        bool_query, 
        sort=Sort(sorters=[FieldSort('l', SortOrder.ASC)]), 
        limit=100, 
        get_total_count=True), 
    ColumnsToGet(return_type=ColumnReturnType.ALL)
)