Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter depth limitation #2568

Merged
merged 8 commits into from
Sep 28, 2023
27 changes: 18 additions & 9 deletions learn/inner_workings/known_limitations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,32 @@ If your query is `Hello - World`:

## Maximum filter depth

**Limitation:** Meilisearch does not accept searches with more than 2000 `OR` filters.
**Limitation:** Meilisearch accepts filtering searches (using the `filter` search parameter) with a maximum filtering depth of 2000.
curquiza marked this conversation as resolved.
Show resolved Hide resolved

**Explanation:** `OR` filters create nested structures which can lead to a stack overflow.
**Explanation:** Regarding filering, the depth increases when mixing and alterning `AND` and `OR` operators filters creating nested structures which can lead to a stack overflow.
curquiza marked this conversation as resolved.
Show resolved Hide resolved

### Example

Either of these filter expressions would cause a search query to fail:
The following filter with the chained `OR` operators corresponds to a depth of 1:
curquiza marked this conversation as resolved.
Show resolved Hide resolved

```sql
user = 1 OR user = 2 […] OR user = 1500 OR user = 1501 […] OR user = 2000 OR user = 2001
user = 1 OR user = 2 […] OR user = 10000
curquiza marked this conversation as resolved.
Show resolved Hide resolved
```

```json
[
["user = 1", "user = 2", […], "user = 1500", "user = 1501", […], "user = 2000", "user = 2001"]
]
```
We got the same behavior with chained `AND` operators: the depth is still 1.
curquiza marked this conversation as resolved.
Show resolved Hide resolved

However, when mixing and alterning `AND` and `OR` operators, we create depths:

```sql
# AND is nested inside the ORs, so we have a depth of 2
id = 1 OR id = 2 AND id = 3

# Here we have a depth of 4
id = 1 OR (id = 2 AND (id = 3 OR (id = 4 AND id = 5)))
curquiza marked this conversation as resolved.
Show resolved Hide resolved

# But here the depth is still 2
id = 1 OR (id = 2 AND id = 3) OR (id = 4 AND id = 5) OR id = 6
```
curquiza marked this conversation as resolved.
Show resolved Hide resolved

## Size of integer fields

Expand Down