redis / docs

Documentation for Redis, Redis Cloud, and Redis Enterprise
https://redis.io/docs/latest/
Other
19 stars 106 forks source link

(Combined query not working on JSON Array objects). "And(&)" operation is not working on each JSON Object with in the JSON Array. Instead it is working as "OR" across all the JSON objects of JSON array in Redis Search. #677

Open shashirangam opened 1 week ago

shashirangam commented 1 week ago

Combined query not working on JSON Array objects.

JSON format:

 {
  "description": "list of items",
  "items": [
    {
      "status": 2,
      "enabled": true,
      "name": "Item1",
      "price": 500
    },
    {
      "status": 0,
      "enabled": true,
      "name": "Item2",
      "price": 1000
    },
    {
      "status": 0,
      "enabled": true,
      "name": "Item2",
      "price": 1200
    }
  ]
}

I created index in different ways as below.

FT.CREATE jindex ON JSON PREFIX 1 jsn: SCHEMA $.description as description TAG $.items.[*].name as name TAG $.items.[*].price as price NUMERIC $.items.[*].status as status NUMERIC

FT.CREATE tindex ON JSON PREFIX 1 jsn: SCHEMA $.description as description TAG $.items.*.name as name TAG $.items.*.price as price NUMERIC $.items.*.status as status NUMERIC

FT.CREATE mindex ON JSON PREFIX 1 jsn: SCHEMA $.description as description TAG $.items.[0:].name as name TAG $.items.[0:].price as price NUMERIC $.items.[0:].status as status NUMERIC

FT.CREATE gindex ON JSON PREFIX 1 jsn: SCHEMA $.description as description TAG $.items[*].name as name TAG $.items[*].price as price NUMERIC $.items[*].status as status NUMERIC

Insert data:

JSON.SET jsn:1 $ '{"description":"list of items","items":[{"status":2,"enabled":true,"name":"Item1","price":500},{"status":0,"enabled":true,"name":"Item2","price":1000},{"status":0,"enabled":true,"name":"Item2","price":1200}]}'

FT.SEARCH jindex '(@status:[0 0]) (@name:{Item1})'

                             (or)

FT.SEARCH jindex '(@status:[0 0]) & (@name:{Item1})'

                             (or)

FT.SEARCH tindex '(@status:[0 0]) (@name:{Item1})'

                             (or)

FT.SEARCH tindex '(@status:[0 0]) & (@name:{Item1})'

                             (or)

FT.SEARCH mindex '(@status:[0 0]) (@name:{Item1})'

                             (or)

FT.SEARCH mindex '(@status:[0 0]) & (@name:{Item1})'

                             (or)

FT.SEARCH gindex '(@status:[0 0]) (@name:{Item1})'

                             (or)

FT.SEARCH gindex '(@status:[0 0]) & (@name:{Item1})'

The above all commands returning one record as in screenshot instead of 0 records. But the status(0) & item(Item1) both are not available in one JSON object.

image

It is breaking our implementation where ever redis-search, business logic depends on json array. Thank you in advance for your quick response.

I am using the redis-stack latest version using docker

docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 -v "D:/storage:/data:rw" redis/redis-stack:latest

shashirangam commented 2 days ago

Reminder...

dwdougherty commented 1 day ago

As Michelle said in your other Issue, we think you may have better luck getting help with your question on our discord server. Here are the instructions to join and ask your question/get help to solve your issue: https://redis.io/learn/community/discord.