#community-help

Sorting Issues with Typesense's `group_by` Param

TLDR Vamshi was puzzled by inconsistent results order in Typesense. Kishore Nallan clarified how group_by sorting works, assisting Vamshi in resolving the problem.

Powered by Struct AI

1

5
3mo
Solved
Join the chat
Aug 22, 2023 (3 months ago)
Vamshi
Photo of md5-14be304e872099e0a38762cb554dcb2c
Vamshi
05:08 AM
Hi everyone! We are seeing that typesense returns data in a random order when using group_by param. I am explicitly providing sort_by to see if that helps as well. Here's an example query
q=skirt&query_by=searchText0,searchText1,searchText2&per_page=10&group_by=productID&group_limit=50&sort_by=publicationDate:desc,rankingScore:desc&filter_by=category:=[`Skirt`]

our cloud typesense cluster version is Typesense v0.24.1 . Am I missing something? Any help is appreciated, thanks.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
05:11 AM
The group_by results are sorted by the a representative element in the group. For e.g. here you are sorting by publicationDate:desc,rankingScore:desc so the record with the greatest publicationDate within each group will become the representative element for that group. Other elements in the group can have a lower value.
Vamshi
Photo of md5-14be304e872099e0a38762cb554dcb2c
Vamshi
05:13 AM
Okay, if the highest element is being chosen as representative element, then the returned results should be in consistent order, right?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
05:14 AM
Yes, the element with highest value in each group should be in order.
Vamshi
Photo of md5-14be304e872099e0a38762cb554dcb2c
Vamshi
05:31 AM
thank you. that helped debug my issue. Not an issue with typesense, but with some post processing on top of that. Thanks!

1