meilisearch icon indicating copy to clipboard operation
meilisearch copied to clipboard

Implements the `EXISTS` filter

Open irevoire opened this issue 3 years ago • 1 comments

After the following discussion and a meeting with @gmourier and @loiclec; https://github.com/meilisearch/product/issues/22

The first version of the filter should be implemented with the following syntax;

The keyword is postfixed
       vvvvv
 price EXISTS
^     ^
A NOT can be prefixed or infixed
vvv       vvv
NOT price NOT EXISTS

With the following set of documents;

{ "id": 1, "product": "T-shirt", "price": 20, "color": "yellow" }
{ "id": 2, "product": "T-shirt", "color": "red" }
  • The filter price EXISTS will select the first document.
  • The filter price NOT EXISTS or NOT price EXISTS will select only the second document.

If a field contains an empty array or a null value, it's considered as existing:

{ "id": 1, "product": "T-shirt", "price": 20, "color": "yellow" }
{ "id": 2, "product": "T-shirt", "price": [], "color": "red" }
{ "id": 3, "product": "T-shirt", "price": null, "color": "red" }
{ "id": 4, "product": "T-shirt", "color": "red" }

Here price EXISTS matches documents 1, 2 and 3.


This will ease the handling of incomplete documents. For example, if you want to return all T-shirt that cost less than 20€ or that doesn't have a price specified, you will be able to write product = "T-shirt" AND (price < 20 OR price NOT EXISTS). That was not possible previously.

irevoire avatar Jun 08 '22 09:06 irevoire

For people following this issue, we have already published a docker tag to test the feature

docker run -it --rm \
    -p 7700:7700 \
    getmeili/meilisearch:v0.29.0-filter.beta.0

Or you can compile the source code on the filter/field-in branch on this repo

All the information about the new addition is detailed here

Any feedback is more than welcome!! ❤️

curquiza avatar Jul 05 '22 11:07 curquiza

I am curious, if my field got value null, does this EXISTS work? I am trying to do a filter UI with the operator option named "Is empty" and "Is not empty" sort of like Notion filter. But it seems like this is not possible.

82kex_21_04_27

Will there be any support in the works or we need to put a value like field = '__SPECIAL_NULL__' fake value to circumvent it?

mech avatar Sep 22 '22 13:09 mech

Hey @mech, Currently, the exists filter matches the documents where the field exists. Existing means the field in the JSON being equal to null doesn't change anything about its existence.

If a field contains an empty array or a null value, it's considered as existing.

What you're asking for would be another feature we've already thought about. It's not planned currently, but I'm going to open a discussion on our product repository, and it would be nice if you could answer me over there so we don't lose any information! https://github.com/meilisearch/product/discussions/539

irevoire avatar Sep 22 '22 13:09 irevoire