dragonflydb / dragonfly

A modern replacement for Redis and Memcached
https://www.dragonflydb.io/
Other
25.27k stars 910 forks source link

FT.SEARCH - search on TAG not working #3511

Closed alexbatis closed 3 weeks ago

alexbatis commented 4 weeks ago

Describe the bug When performing a FT.SEARCH query on a TAG field on a JSON document, no results are returned. However, the same functionality works both on a HASH document in dragonfly and a JSON document using redisearch

To Reproduce Steps to reproduce the behavior:

  1. Create the index:
    FT.CREATE "json_city" ON JSON PREFIX 1 json_city: SCHEMA "$[\"name\"]" AS name TAG SEPARATOR | "$[\"population\"]" AS population NUMERIC SORTABLE "$[\"continent\"]" AS continent TAG SEPARATOR |
  2. Create the records:
    JSON.SET "json_city:01J57VZMXMTXNA912J4BV2NFV8" $ "{\"name\":\"London\",\"population\":8.8,\"continent\":\"Europe\"}"
    JSON.SET "json_city:01J57VZMXZEF6WFQ5CS29JHP4F" $ "{\"name\":\"Athens\",\"population\":3.1,\"continent\":\"Europe\"}"
    JSON.SET "json_city:01J57VZMXZXMS9EZ1QFH0YFS24" $ "{\"name\":\"Tel-Aviv\",\"population\":1.3,\"continent\":\"Asia\"}"
    JSON.SET "json_city:01J57VZMY0Z1VY8WH7X784CFA8" $ "{\"name\":\"Hyderabad\",\"population\":9.8,\"continent\":\"Asia\"}"
  3. Query all records to ensure index is setup correctly:
    FT.SEARCH json_city *
  4. Search for cities that have Europe as the TAG attribute continent.
    FT.SEARCH json_city "(@continent:{Europe})"
  5. Observe no results found
    127.0.0.1:6379> FT.SEARCH json_city "(@continent:{Europe})"
    1) (integer) 0

Expected behavior Expected behavior would be that cities with the continent field matching Europe would be found, like they are when using hashes or redisearch. This behavior is outlined in the dragonfly FT.SEARCH docs.

Screenshots dragonfly (not working as expected):

image

dragonfly docs:

Screenshot 2024-08-14 at 2 56 23 AM

dragonfly (working example using hashes) - taken from dragonfly search announcement example:

image

redis-stack (uses exact same code as reproduction steps above and demonstrates expected behavior)

Screenshot 2024-08-14 at 3 05 15 AM Screenshot 2024-08-14 at 3 05 25 AM Screenshot 2024-08-14 at 3 05 31 AM Screenshot 2024-08-14 at 3 05 37 AM

Environment (please complete the following information):

Reproducible Code Snippet

FT.CREATE "json_city" ON JSON PREFIX 1 json_city: SCHEMA "$[\"name\"]" AS name TAG SEPARATOR | "$[\"population\"]" AS population NUMERIC SORTABLE "$[\"continent\"]" AS continent TAG SEPARATOR |

JSON.SET "json_city:01J57VZMXMTXNA912J4BV2NFV8" $ "{\"name\":\"London\",\"population\":8.8,\"continent\":\"Europe\"}"
JSON.SET "json_city:01J57VZMXZEF6WFQ5CS29JHP4F" $ "{\"name\":\"Athens\",\"population\":3.1,\"continent\":\"Europe\"}"
JSON.SET "json_city:01J57VZMXZXMS9EZ1QFH0YFS24" $ "{\"name\":\"Tel-Aviv\",\"population\":1.3,\"continent\":\"Asia\"}"
JSON.SET "json_city:01J57VZMY0Z1VY8WH7X784CFA8" $ "{\"name\":\"Hyderabad\",\"population\":9.8,\"continent\":\"Asia\"}"

FT.SEARCH json_city *

FT.SEARCH json_city "(@continent:{Europe})"

Additional context Code for working hash example:

FT.CREATE cities PREFIX 1 city: SCHEMA name TEXT population NUMERIC SORTABLE continent TAG
HSET city:1 name London population 8.8 continent Europe
HSET city:2 name Athens population 3.1 continent Europe
HSET city:3 name Tel-Aviv population 1.3 continent Asia
HSET city:4 name Hyderabad population 9.8 continent Asia
FT.INFO cities
FT.SEARCH cities '@continent:{Europe}' SORTBY population DESC LIMIT 0 1 RETURN 2 name population
FT.SEARCH cities '@population:[0 5] @continent:{Asia}' RETURN 1 name

I've also tried escaping the string in many different ways, as some other issues mention incorrect query formatting. as dragonfly is intended to be a drop in redis replacement i would hope that i wouldn't need to format the query in a different way to get it to work.

FT.SEARCH json_city "(@continent:{Europe})"
FT.SEARCH json_city (@continent:{Europe})
FT.SEARCH json_city "@continent:\{Europe\}"
FT.SEARCH json_city "@continent:\{'Europe'\}"

My ultimate goal is to get this type of query working with redis-om-node

Thanks for your help!

dranikpg commented 4 weeks ago

Hi @alexbatis. Looks like we have an interfacing issue with our new improved json backend 😢

We'll fix this issue in our next release, for now you can run Dragonfly with --jsonpathv2=false. I checked and it works

alexbatis commented 4 weeks ago

thanks for the workaround @dranikpg. i'll watch out for the next release and give it another try then