Is it possible to use RedisJson and RedisSearch to filter objects by the length of array property?

275 Views Asked by At

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)

1

There are 1 best solutions below

2
Adriano Amaral On

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.