redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.12k stars 112 forks source link

Filter by "list field contains value" #248

Closed DennyD17 closed 2 years ago

DennyD17 commented 2 years ago

Hi! Is there a way to find docs, indexed ListField of that, contains some string?

At example, I have the model:

class Block(JsonModel):
    strings: List[str] = Field(index=True)

and I want to find all docs that contains string "foo" in field "strings". Can I make that query?

simonprickett commented 2 years ago

Hi there - you should be able to yes, check out the example here:

https://github.com/redis-developer/redis-om-python-flask-skeleton-app/blob/6d5a18e0f7ac53681e5e01c079a5abb68b694bf1/app.py#L86

Here's the accompanying model:

https://github.com/redis-developer/redis-om-python-flask-skeleton-app/blob/main/person.py

And a video walkthrough of this sample application:

https://www.youtube.com/watch?v=PPT1FElAS84

DennyD17 commented 2 years ago

It works, thanks a lot!

simonprickett commented 2 years ago

@DennyD17 no problem - one of the things on my list is to document the find operators more thoroughly. #144