in and notin

更新时间:
复制 MD 格式

Functionality functions

The fields that you reference in the parameters of functionality functions must be configured as index or attribute fields based on the description of each function.

A document field used as a function parameter must be configured as an index or an attribute, as required by the specific function.

in or notin: judges whether field values are in a specific list

1. Syntax

in(field, "number1|number2")notin(field, "number1|number2")

2. Parameters

field: the name of the field to be judged. Only fields of the INT, LITERAL, FLOAT, or DOUBLE type are supported. Fields of the ARRAY or TEXT type and the analyzer for fuzzy searches are not supported. number N: the elements in a set. Separate multiple elements with vertical bars (|). Each element must be a string.

3. Return values

true/false

4. Scenarios

Scenario 1: Retrieve documents that contain "iphone" and the type field whose value is 1, 2, or 3. The type field must be of the INT type.

query=default:'iphone'&&filter=in(type, '1|2|3')

Scenario 2: Retrieve documents that contain "iphone" and the type field whose value is not 1, 2, or 3. The type field must be of the INT32 type.

query=default:'iphone'&&filter=notin(type, '1|2|3')

5. Usage notes

  • The field that you reference in the parameters of the functions must be configured as an attribute field.

  • If you use the in or notin function in filter clauses, you cannot use fields of the ARRAY type. Otherwise, the following syntax error with an error code of 6141 is returned: Filter clause syntax error.

  • The function in(field, "value1|value2") is equivalent to (field = value1) OR (field = value2). However, the in function offers better performance. The same principle applies to the notin function.

  • Providing a large number of values (for example, thousands) to the in or notin function can significantly degrade query performance. A longer value list increases the computational overhead for filtering, which can lead to higher query latency or even a timeout.

  • If you must pass a large number of values, split the list into smaller batches (for example, 500 values or less per batch) for separate queries and then combine their results.