All Products
Search
Document Center

OpenSearch:filter clause

Last Updated:Apr 01, 2026

A filter clause narrows search results by evaluating conditions against attribute fields. After a query clause retrieves candidate documents, the filter clause keeps only those that match the specified conditions.

Syntax

{
  "filter": "<expression>"
}

The filter clause is optional. The value is a string containing a logical expression, such as price > 100 AND categoryId = 10.

All fields used in a filter clause must be attribute fields defined in schema.json.

Field type constraints

Before writing filter expressions, review the constraints for each field type:

Field typeSupported operatorsNotes
Numeric (INTEGER, FLOAT, DOUBLE)> < = <= >= !=For FLOAT and DOUBLE, avoid =. Floating-point precision makes exact equality checks unreliable. Use > or < instead.
STRING= !=Enclose values in double quotation marks ("). Escape double quotation marks that appear inside values. Cannot use > or <. Cannot use arithmetic operators.
Multi-value field= !=Returns documents where the field contains the condition value, not where it equals it exactly.
BOOLEAN (function return)(none required)Built-in functions that return BOOLEAN do not require a relational operator.

Expression syntax

Quick reference

GoalExpressionResult
Numeric comparisonprice > 100Documents where price is greater than 100
String exclusionprovince != "Zhejiang"Documents where province is not Zhejiang
Multi-value matchids = 1Documents where the ids field contains 1
AND combinationprice > 100 AND categoryId = 10Documents matching both conditions
OR combinationcategoryId = 100 OR categoryId = 10Documents matching either condition
Grouped OR with AND(categoryId = 100 OR categoryId = 10) AND price > 100Documents in either category with price above 100
Arithmetic in filterprice * 0.5 > 100Documents where half the price exceeds 100
Field arithmeticprice - cost > 100Documents where the margin exceeds 100
Built-in functionin(id,"1|2|3")Documents where id is 1, 2, or 3

Single condition

<left operand> <relational operator> <right operand>
  • Left operand: an attribute field or a constant (numeric or string)

  • Relational operator: > < = <= >= !=

  • Right operand: an attribute field or a constant (numeric or string)

Examples:

price > 100
ids = 1
province != "Zhejiang"

Multiple conditions

<condition> <logical operator> <condition>
  • Logical operators: AND, OR

    • AND returns documents matching both conditions.

    • OR returns documents matching either condition.

  • Use parentheses () to control evaluation priority.

Examples:

price > 100 AND categoryId = 10
categoryId = 100 OR categoryId = 10
(categoryId = 100 OR categoryId = 10) AND price > 100

Arithmetic in filter conditions

<left operand> <arithmetic operator> <right operand> <relational operator> <condition value>
  • Arithmetic operators: + - * /

  • Left operand: an attribute field or a constant (numeric or string)

  • Right operand: an attribute field or a constant (numeric or string)

  • Condition value: an attribute field or a constant

Examples:

price * 0.5 > 100
price - cost > 100
(price * 0.5 > 100) AND categoryId = 10

Built-in functions

<function> <relational operator> <right operand>

Built-in functions such as in and notin can be used as the left operand. If the function returns a BOOLEAN value, omit the relational operator. A function can also appear as the right operand of a relational operator.

For the full list of built-in functions, see Built-in functions.

Example:

in(id,"1|2|3")

This returns documents where the id field contains 1, 2, or 3.