#community-help

Sorting JSON Collection by Specific ID Order

TLDR GM asked how to sort JSON results by specific IDs. Jason suggested using pinned_hits parameter or sorting results client-side.

Powered by Struct AI
3
4mo
Solved
Join the chat
May 30, 2023 (4 months ago)
GM
Photo of md5-9f364f57af6f71faaf6ea963342ef3f6
GM
07:11 PM
HI Team, i have JSON collection ,i am searching by ids like 2,59,8,9 and need result in same order as i mentioned in ids.that means what ever out put releated ID 2 should come first,then 59 ,then 8,then 9..how to achive
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:12 PM
You could use the pinned_hits parameter for this, but you will have to repeat the IDs in both pinned hits and also filter_by
08:13
Jason
08:13 PM
Alternatively, if you already know the order of the IDs when sending it in the filter_by parameter, you could then sort the results from Typesense on the client-side using the same sort oder