Search code examples
pythonpython-3.xredisearch

Filter search by tags with python redisearch client


I have an index with a TagField, created like this

create_index([TextField("enc_id"), TextField("title", 2.0), TagField("tags")])

I would add a document like this.

add_document(title = "meh, lol", tags = "python,C")

I search like this. It has a few fields that don't need to be searched, so I limited fields to search.

Query(query_string='meh').limit_fields(title)

What I want is to also filter results by some tags. For example, I have documents with tags like python, C, Java and I only want documents to be returned that has the tag 'C'.

How do I do that?


Solution

  • Finally found it :D.

    I basically tried to execute pure redis-cli commands with the python client. Didn't know how :/

    But this worked. I can use @ in the query string. Just like we do in cli.

    Query("@title:meh @tags:{java}")