You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use arithmetic operators like `==`, `!=`, `<`, `>`, `<=`, `>=`. For a full list of arithmetic operators available in Milvus, refer to [Arithmetic Operators](basic-operators.md#Arithmetic-Operators).
214
+
Use arithmetic operators like `==`, `!=`, `<`, `>`, `<=`, `>=`. For a full list of arithmetic operators available in Milvus, refer to [Arithmetic operators](basic-operators.md#Arithmetic-operators).
215
215
216
216
The example below filters entities with timestamps (`tsz`) that are not equal to **2025-01-03T00:00:00+08:00**:
217
217
@@ -434,4 +434,4 @@ For step-by-step instructions and code samples, refer to the dedicated pages:
434
434
435
435
By default, queries on `TIMESTAMPTZ` fields without an index will perform a full scan of all rows, which can be slow on large datasets. To accelerate timestamp queries, create an `STL_SORT` index on your `TIMESTAMPTZ` field.
For more details about choosing between `LIKE` and regex, supported field types, regex syntax, escaping rules, and performance, refer to [Pattern Matching](pattern-matching.md). Milvus also allows you to build an `NGRAM` index on `VARCHAR` fields or JSON string paths to accelerate eligible pattern matching filters. For details, refer to [NGRAM](ngram.md).
118
118
119
-
## Arithmetic Operators
119
+
## Arithmetic operators
120
120
121
121
Arithmetic operators allow you to create conditions based on calculations involving numeric fields.
122
122
123
-
### Supported Arithmetic Operators:
123
+
### Supported arithmetic operators
124
124
125
125
-`+` (Addition)
126
126
@@ -134,59 +134,110 @@ Arithmetic operators allow you to create conditions based on calculations involv
134
134
135
135
-`**` (Exponentiation)
136
136
137
-
### Example 1: Using Modulus (`%`)
137
+
### Example 1: Using modulus (`%`)
138
138
139
139
To find entities where the `id` is an even number (i.e., divisible by 2):
140
140
141
141
```python
142
142
filter='id % 2 == 0'
143
143
```
144
144
145
-
### Example 2: Using Exponentiation (`**`)
145
+
### Example 2: Using exponentiation (`**`)
146
146
147
147
To find entities where `price` raised to the power of 2 is greater than 1000:
148
148
149
149
```python
150
150
filter='price ** 2 > 1000'
151
151
```
152
152
153
-
## Logical Operators
153
+
## Bitwise operators | Milvus 3.0.0+
154
+
155
+
Bitwise operators are useful when an integer field encodes multiple flags, such as permissions, feature flags, or status bits. You can use these operators in filter expressions to check, combine, or compare individual bits in an integer value.
156
+
157
+
For scalar fields, bitwise operators apply to integer field types, such as `INT8`, `INT16`, `INT32`, and `INT64`.
158
+
159
+
### Supported bitwise operators
160
+
161
+
| Operator | Name | Typical use |
162
+
| --- | --- | --- |
163
+
|`&`| Bitwise AND | Check whether specific bits are set. |
164
+
| <code>|</code> | Bitwise OR | Combine bits before comparison. |
165
+
|`^`| Bitwise XOR | Compare bit differences between two values. |
166
+
167
+
### Example: Filtering by permission bits
168
+
169
+
Assume you have an integer field named `permissions`, and each bit in the integer represents a permission flag:
170
+
171
+
| Permission flag | Bit value |
172
+
| --- | --- |
173
+
|`READ`|`1`|
174
+
|`WRITE`|`2`|
175
+
|`SHARE`|`4`|
176
+
|`ADMIN`|`8`|
177
+
178
+
For example, `permissions = 5` means that the `READ` and `SHARE` bits are set, because `5 = 1 + 4`.
179
+
180
+
To find entities where the `SHARE` bit is set, use bitwise AND (`&`):
181
+
182
+
```python
183
+
filter="(permissions & 4) == 4"
184
+
```
185
+
186
+
To find entities where setting the `WRITE` bit produces the `READ + WRITE + SHARE` permission set, use bitwise OR (`|`):
187
+
188
+
```python
189
+
filter="(permissions | 2) == 7"
190
+
```
191
+
192
+
To find entities whose permission bits differ from `READ + WRITE + SHARE` by only the `WRITE` bit, use bitwise XOR (`^`):
193
+
194
+
```python
195
+
filter="(permissions ^ 7) == 2"
196
+
```
197
+
198
+
<divclass="alert note">
199
+
200
+
Always wrap the bitwise operation in parentheses before comparing the result, such as `(permissions & 4) == 4`. Milvus 3.0.0 supports `&`, `|`, and `^` in filter expressions. Bitwise NOT (`~`) and shift operators (`<<` and `>>`) are not supported.
201
+
202
+
</div>
203
+
204
+
## Logical operators
154
205
155
206
Logical operators are used to combine multiple conditions into a more complex filter expression. These include `AND`, `OR`, and `NOT`.
156
207
157
-
### Supported Logical Operators:
208
+
### Supported logical operators
158
209
159
210
-`AND`: Combines multiple conditions that must all be true.
160
211
161
212
-`OR`: Combines conditions where at least one must be true.
162
213
163
214
-`NOT`: Negates a condition.
164
215
165
-
### Example 1: Using `AND` to Combine Conditions
216
+
### Example 1: Using `AND` to combine conditions
166
217
167
218
To find all products where `price` is greater than 100 and `stock` is greater than 50:
168
219
169
220
```python
170
221
filter='price > 100 AND stock > 50'
171
222
```
172
223
173
-
### Example 2: Using `OR` to Combine Conditions
224
+
### Example 2: Using `OR` to combine conditions
174
225
175
226
To find all products where `color` is either "red" or "blue":
176
227
177
228
```python
178
229
filter='color == "red" OR color == "blue"'
179
230
```
180
231
181
-
### Example 3: Using `NOT` to Exclude a Condition
232
+
### Example 3: Using `NOT` to exclude a condition
182
233
183
234
To find all products where `color` is not "green":
184
235
185
236
```python
186
237
filter='NOT color == "green"'
187
238
```
188
239
189
-
## IS NULL and IS NOT NULL Operators
240
+
## IS NULL and IS NOT NULL operators
190
241
191
242
The `IS NULL` and `IS NOT NULL` operators are used to filter fields based on whether they contain a null value (absence of data).
192
243
@@ -200,7 +251,7 @@ The operators are case-insensitive, so you can use `IS NULL` or `is null`, and `
200
251
201
252
</div>
202
253
203
-
### Regular Scalar Fields with Null Values
254
+
### Regular scalar fields with null values
204
255
205
256
Milvus allows filtering on regular scalar fields, such as strings or numbers, with null values.
206
257
@@ -228,7 +279,7 @@ To retrieve entities where the `description` field is not null and the `price` f
228
279
filter='description IS NOT NULL AND price > 10'
229
280
```
230
281
231
-
### JSON Fields with Null Values
282
+
### JSON fields with null values
232
283
233
284
Milvus allows filtering on JSON fields that contain null values. A JSON field is treated as null in the following ways:
234
285
@@ -296,7 +347,7 @@ filter = 'metadata IS NOT NULL'
296
347
# ]
297
348
```
298
349
299
-
### ARRAY Fields with Null Values
350
+
### ARRAY fields with null values
300
351
301
352
Milvus allows filtering on ARRAY fields that contain null values. An ARRAY field is treated as null in the following ways:
302
353
@@ -362,7 +413,7 @@ filter = 'tags IS NOT NULL'
362
413
# ]
363
414
```
364
415
365
-
## Tips on Using Basic Operators with JSON and ARRAY Fields
416
+
## Tips on using basic operators with JSON and ARRAY fields
366
417
367
418
While the basic operators in Milvus are versatile and can be applied to scalar fields, they can also be effectively used with the keys and indexes in the JSON and ARRAY fields.
Copy file name to clipboardExpand all lines: v3.0.x/site/en/userGuide/search-query-get/boolean/boolean.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,11 @@ Milvus supports several basic operators for filtering data:
18
18
19
19
-**Arithmetic Operators**: `+`, `-`, `*`, `/`, `%`, and `**` are used for calculations involving numeric fields.
20
20
21
+
-**Bitwise Operators**: In Milvus 3.0.0 and later, `&`, `|`, and `^` filter integer fields that encode multiple flags, such as permissions or status bits. For details, refer to [Basic Operators](basic-operators.md#Bitwise-operators).
22
+
21
23
-**Logical Operators**: `AND`, `OR`, and `NOT` combine multiple conditions into complex expressions.
22
24
23
-
-**IS NULL and IS NOT NULL Operators**: The `IS NULL` and `IS NOT NULL` operators are used to filter fields based on whether they contain a null value (absence of data). For details, refer to [Basic Operators](basic-operators.md#IS-NULL-and-IS-NOT-NULL-Operators).
25
+
-**IS NULL and IS NOT NULL Operators**: The `IS NULL` and `IS NOT NULL` operators are used to filter fields based on whether they contain a null value (absence of data). For details, refer to [Basic Operators](basic-operators.md#IS-NULL-and-IS-NOT-NULL-operators).
24
26
25
27
### Example: Filtering by Color
26
28
@@ -30,6 +32,14 @@ To find entities with primary colors (red, green, or blue) in a scalar field `co
30
32
filter='color in ["red", "green", "blue"]'
31
33
```
32
34
35
+
### Example: Filtering by Permission Bits
36
+
37
+
To find entities whose integer `permissions` field has the `SHARE` bit set, use the bitwise AND operator (`&`):
38
+
39
+
```python
40
+
filter='(permissions & 4) == 4'
41
+
```
42
+
33
43
### Example: Filtering by Regex Pattern
34
44
35
45
To find entities whose `message` field contains an error code such as `E1001`, use the regex match operator `=~`:
0 commit comments