how to query for absence/empty field

I am using a tag field to store discrete values that I later query on:
ft.create t schema make tag

How can I query for all documents that do NOT have this field / or empty?

kinda: ’ select * from t where make eq “” ’

Michael

P.S. I just had a lot of fun attending RedisConf19 - thank you for making it happen!

Unfortunately this is not practical due to how indexes are stored. We use inverted indexes, which means that each term contains the list of documents which contain it. If we were to index the absence of a field, this would substantially inflate the index size and increase our indexing time, because every single field which may be empty but in the schema would need to be indexed with the implicit NULL value.

If you are concerned about a specific field being present, and if this is an option, perhaps a de-facto tag field, e.g. field_foo_empty.

I suppose this might also be possible using aggregations as well (although I don’t have this implemented, there are no needle-in-haystack limitations).

Mark Nunberg | Senior Software Engineer
Redis Labs - home of Redis

Email: mark@redislabs.com

1 Like

Just to expand on what Mark has said as this pattern deserves an example, I’ve had to accomplish this previously and have used a tag field with tags to indicate emptiness.

Say you have 3 fields, foo, bar, and baz.

Then you’d have your schema like this:

FT.CREATE myindex

SCHEMA

foo TEXT

bar TEXT

baz TEXT

emptiness TAG

Then when you add a document with two of the fields empty, you would do:

FT.ADD myindex … FIELDS baz “something” emptiness “foo, bar”

Finally, searching for the empty field(s):

FT.SEARCH myindex “@emptiness:{ foo } @emptiness:{ bar }”

Hope that makes it more clear!

-K

OK, thanks for the clear answers. I am using tags now to indicate missing values, but I like the idea of having a dedicated tag field for that. That way, I can populate the field automatically at index time, and I know that only the indexer manages the contents of that field.

Michael