1

If I have multiple keys of JSON type in Redis DB that have the following form (Each key have different amount of users)

{
    "users": [
        {
            "name": "Alice",
            "age": 15
        },
        {
            "name": "Bob",
            "age": 20
        }
    ]
}

By using RedisJson and RedisSearch, How can I filter all the objects that their users.length > or < or = to X ? (for example, get all the objects with users.length > 10)

user16217248
  • 3,119
  • 19
  • 19
  • 37
Yaniv
  • 63
  • 6

1 Answers1

2

currently length is not supported as JSONPath expression. As a workaround, you can use JSON.ARRLENhttps://redis.io/commands/json.arrlen/ command and execute the logic on the application/client side.

  • 1
    I've ended up adding logic on the object insertion and added an additional field of the array length. – Yaniv May 10 '23 at 14:54
  • you can also use redisGears to do that on the server side, if you really want to – A. Guy May 10 '23 at 15:50