Complex TAG query

Hi, let’s say I have an index with a TAG field. My goal is to search for documents that have the “food” tag OR that have BOTH the “drink” and “alcoholic” tags.
I can’t find a way to express this in a single query, is it possible?

Thanks for your help.

Take a look at the SET data structure. You can create a set for “food”, “drink” and “alcoholic” And then query them to get the results you want. Here are some indeas:

There’s a couple good chapters in the Redis in Action eBook:

Thank you for your answer, but I don’t think that’s what I want. I’m using Redisearch and those kind of sets are built automatically for each tag, it seems stupid to do manually almost the same thing. If it is possible, I would like to achieve the result only with one RediSearch tag query.

Thank you for your reply, I hope you can help me futher.

This should work:> FT.CREATE idx SCHEMA t TAG
OK> FT.ADD idx doc1 1.0 FIELDS t food
OK> FT.ADD idx doc2 1.0 FIELDS t "drink,alcoholic"
OK> FT.ADD idx doc3 1.0 FIELDS t "foo"
1) (integer) 3
2) "doc3"
3) 1) "t"
   2) "foo"
4) "doc2"
5) 1) "t"
   2) "drink,alcoholic"
6) "doc1"
7) 1) "t"
   2) "food"> FT.SEARCH idx "(@t:{food})|((@t:{drink} @t:{alcoholic}))"
1) (integer) 2
2) "doc2"
3) 1) "t"
   2) "drink,alcoholic"
4) "doc1"
5) 1) "t"
   2) "food">
1 Like

If this works, you are my saviour! I’ve already tried similar queries, but maybe I was missing some parenthesis. I will try this ASAP and let you know, thanks!

1 Like

It works flawlessly, thank you!

1 Like