The escaping on the backslash itself behaves weird in Redis. The context is that I need to index a document but want to avoid the impact on the backslash (escape separator) if the document contains the backslash.
1 I tried indexing on text “login\ today”. From my understanding, the text should be tokenized into two worlds “login” and “today” because the escaping on the backslash itself the space will be as is and thus separate the words. ft.create test_idx on hash prefix 1 “test:doc:” schema detail text hset test:doc:doc1 detail “login\ today”
However, when I searched for “today”, it returns nothing.
ft.search test_idx “today”
If I searched for “login\today”, the document was retrieved.
ft.search test_idx “login\\today”
I’m very confused and didn’t why.
2 I also found something else.
127.0.0.1:6379> ft.explaincli test_idx "login\\\\today"
1) UNION {
2) logintoday
3) +logintoday(expanded)
4) }
I though it should have searched for “logintoday” but some of the middle backslashes are stripped. I’m using redis_version:6.2.11 and search:2.6.7
I would appreciate if anyone can answer my questions.
Thank you so much.
Zhen Xia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.