Does RediSearch Aggregations support ranges?

Hi all,

Do you know if RediSearch Aggregations supports ranges? If so, how can I accomplish this?

I have multiple users in my RediSearch index with one field being Age. Now I want to do an aggregation on age, a count, but I want the result being Age ranges: eg: 0 - 10 years, 10 - 20 years, 20 - 30 years etc.

Regards,

Davy

I can’t see how it’s possible now, but I don’t see why it shouldn’t be possible in the future fairly simply. The result of the age grouping would need to be passed along as input to GROUPBY which in turn would group based on the contents of that field. Right now we do this for timestamps (where we can produce the year, day, month, etc. of a given timestamp into a value).

Mark Nunberg | Senior Software Engineer
Redis Labs - home of Redis

Email: mark@redislabs.com

So for now it will only by possible that have that Age range values added to the index, I guess?

In the future it would be nice to create custom ranges or do some other mapping on existing values before the GROUPBY kicks in.

Very true - we’re actually working on this, but the ETA is currently unknown.

Actually, you can do age ranges! Perhaps not the most efficiently, but possible.

APPLY "abs((@timestamp - 1535632766) / 31557600)" as age APPLY "@age > 1 && @age < 3" as is1to3

1535632766 is the current timestamp, 31557600 is seconds per year (it won’t take into account leap year or extra seconds, but it’s pretty close).

-K

Can you explain how you would reduce them? 1to3 and 4to7 etc. are distinct fields, but groupby works on values
Mark Nunberg | Senior Software Engineer
Redis Labs - home of Redis

Email: mark@redislabs.com

Slightly different approach, but same basics.

APPLY "abs((@timestamp - 1535632766) / 31557600)" as age APPLY "((@age > 1 && @age < 3) * 1) + ((@age > 3 && @age < 5) * 2) + ((@age > 5 && @age < 6) * 3)" as range GROUPBY 1 @range REDUCE count 0 as agegroups

-K

Very clever, so basically you assign different numerical values based on the boolean-to-integer result of the conditional expressions. He would still need to map them though
Mark Nunberg | Senior Software Engineer
Redis Labs - home of Redis

Email: mark@redislabs.com

Yup. It’s not straightforward, but it’s do-able. I would put upper and lower bounds on this thing just so you don’t get a range 0. YMMV with performance but seems to be decent in a moderate (121k) data set.

-K

It would still be nice to have a deliberate mapping, maybe something like, uh… SETIF . Then one could do:


SETIF “@age > 4 && @age < 8” age_range four_to_eight

SETIF “@age >= 8 && age <= 12” age_range eight_to_twelve

GROUPBY 1 @age_range REDUCE COUNT 0

Mark Nunberg | Senior Software Engineer
Redis Labs - home of Redis

Email: mark@redislabs.com