How to sort the same field by two different criteria

Hi,

I have an integer field that has only positive values with some exceptions where we are setting a -1 value.
I need to sort for that field ascendent, but keep the -1 values at the end.
Is there a way of doing this with redis search without the need of having a second “control” field or calling the search twice?

Thanks in advance,
Daniel Duarte

You can use APPLY in ft.aggregate e.g.

ft.aggregate idx * LOAD 1 a APPLY @a/abs(@a)*-1 as b SORTBY 4 @b ASC @a ASC

This will make sure all the negative numbers are going after the positive numbers.

1 Like