1

I'm using the modules RedisJSON and RediSearch together to perform search queries on JSON data. Given a json list like this:

{"email": "test1@example.com", "is_checked": 1}

I do:

FT.CREATE myidx ON JSON SCHEMA $.email AS email TAG
FT.SEARCH myidx "@email:'test1@example.com'"

but I got Syntax error

How can I select with the value "test1@example.com"?

Akshay G
  • 2,070
  • 1
  • 15
  • 33
LeMoussel
  • 5,290
  • 12
  • 69
  • 122

2 Answers2

2

You can escape special characters, like @, with a backslash:

FT.SEARCH myidx "@email:'test1\@example.com'"

That should do the trick.

Guy Royse
  • 2,739
  • 12
  • 9
2

I just ran into this issue and the accepted answer didn't work for me, but I found a solution in this RediSearch issue.

With an index where there's an email field stored as a TAG you can do a search like this:

FT.SEARCH myidx "@email:{ test1\\@example\\.com }"

With the @ and . characters escaped.

Here are the docs for querying on TAG fields as well: https://redis.io/docs/stack/search/reference/tags/#querying-tag-fields

jket
  • 418
  • 6
  • 9
  • This is the correct answer, as it prevents the tokenization of the value on the '.' and properly uses the '}' since the field is defined as a TAG. – Robin Mar 30 '23 at 15:39