All Products
Search
Document Center

:in and notin

Last Updated:Sep 09, 2021

Functionality functions

You can use functionality functions in filter clauses to define filter conditions. Functionality functions that return numeric values can be used in sort clauses for sorting.

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.

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 or FLOAT type are supported. Fields of the ARRAY, LITERAL, 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 value:

true or 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, an syntax error is returned. The error code is 6141 and the error message is Filter clause syntax error.

  • Both the in(field, "number1|number2") function and the (field = number1) OR (field = number2) syntax can judge whether field values are in a specific list. However, the in function performs better. This rule also applies to the notin function.