When you use the boolean query feature to query data based on a search index, make sure that the subquery conditions in the query are not empty. If the parameters in the subquery are empty, the query cannot be initiated. Check whether the subquery conditions are empty before you query data.
Problem description
The [bool_query] sub query must not be null error message appears when the boolean query feature is used to query data based on a search index. Sample error:
com.alicloud.openservices.tablestore.TableStoreException: [bool_query] sub query must not be null
at com.alicloud.openservices.tablestore.core.CallbackImpledFuture.getResultWithoutLock(CallbackImpledFuture.java:107)
at com.alicloud.openservices.tablestore.core.CallbackImpledFuture.get(CallbackImpledFuture.java:89)
at com.alicloud.openservices.tablestore.SyncClient.waitForFuture(SyncClient.java:575)
at com.alicloud.openservices.tablestore.SyncClient.search(SyncClient.java:490)
at com.ckb.easy.goods.tablestore.util.TableStoreMultipleIndexUtils.search(TableStoreMultipleIndexUtils.java:205)
at com.ckb.easy.goods.tablestore.util.TableStoreMultipleIndexUtils.search(TableStoreMultipleIndexUtils.java:128)
at com.ckb.easy.goods.tablestore.util.TableStoreMultipleIndexUtils.search(TableStoreMultipleIndexUtils.java:96)Cause
The subquery conditions are empty and the required parameters are not configured.
Solution
Check the parameter configurations in the subquery and make sure that all subquery conditions are correctly configured. For more information, see Boolean query.
References
When you use the boolean query feature to query data, the subquery can be of any query type including BoolQuery. You need to check the parameter configurations by referring to different documentations based on the query type. For example, if the subquery is of the TermQuery type, you can configure parameters as described in Term query. The following table describes the query types.
Query type | Description |
This query uses exact matches to retrieve data from the data table. A term query is similar to a query based on string match. If the field is of the TEXT type, Tablestore tokenizes the field values and finds any tokens that exactly match the specified value. | |
This query retrieves data within the specified range from the data table. If the field is of the TEXT type, Tablestore tokenizes the field values and finds any tokens that fall within the specified range. | |
This query retrieves data that contains the specified prefix from the data table. If the field is of the TEXT type, Tablestore tokenizes the field values and finds any tokens that match the specified prefix. | |
This query retrieves data in the data table based on approximate matches. If the field is of the TEXT type, Tablestore tokenizes the field values and the query keyword by using the specified analyzer and finds tokens based on approximate matches. | |
This query allows you to specify wildcard characters including asterisks (*) and question marks (?) in the value to match. An asterisk (*) matches a string of any length, and a question mark (?) matches a single character. The value to match can start with an asterisk (*) or a question mark (?). | |
This query is similar to a match query, except that a match phrase query evaluates the positions of tokens. A row meets the query condition only if the order and positions of the tokens in the row match the specified order and positions. If the tokenization method for the column that you want to query is fuzzy tokenization, the match phrase query delivers a quicker response than the wildcard query. | |
An exists query is also called a NULL query or a NULL-value query. This query is used in sparse data to determine whether a column of a row exists. For example, you can query the rows in which the address column is not NULL. If you want to check whether a column contains NULL values, use an exists query with the NOT operator. | |
This query is similar to a term query. A terms query supports multiple query keywords. A row of data is returned if at least one of the keywords matches the field value. Terms queries are equivalent to the IN operator in SQL statements. | |
This query retrieves data in the data table based on a combination of subqueries. Tablestore returns the rows that match the subqueries. Each subquery can be of any query type. | |
Geo query | Geo queries include geo-distance queries, geo-bounding box queries, and geo-polygon queries. Geo queries are available only for geo fields.
|
This query retrieves the data in the child rows of nested fields. Nested queries are available only for nested fields. To query a nested field, you must specify subqueries and configure the query type and value of each subquery. |