#community-help

Quick Retrieval of Min, Max, and Median Values from Search Query

TLDR Prajjval sought a more efficient way to find the min, max, and median values from a search query result. Jason suggested faceting. However, Prajjval clarified that faceting prolonged document upload due to a data type error, which was later resolved.

Powered by Struct AI
6
31mo
Solved
Join the chat
Apr 24, 2021 (31 months ago)
Prajjval
Photo of md5-1887cf6d03da176cbacb51c666d02d1b
Prajjval
02:14 PM
Is there an easy way to get range of values from a particular field after a search query?
For e.g. lets say I have a collection with 100k documents with two fields : "name" (string) and "price"(float). I perform a search that returns 10k documents, which can be displayed at max 250 documents / page - so 40 pages. I want to figure out the min, median, and max price values across the 10k returned documents. The only way I can think of is to retrieve values from page #1 (min price), page#21 (median price), and page#40(max price) if my results are sorted on price:asc.

Is there a simpler way to retrieve a list of all price values from the 10k documents, so I can get the min,max,median more easily?
02:19
Prajjval
02:19 PM
Btw I have also tried to facet on the "price" field, but that takes an inordinate amount of time, so I assumed that is probably not the most efficient way to go, esp as my collection size increases
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:59 PM
Hi Prajjval, faceting on price would be the way to get min max avg. I’m surprised to hear that it takes a long time. The songs demo for example has 32M records and for every search we facet on artist, genre, release date, etc and it still returns in less than a second.

Could you share the exact query you’re using?
05:58
Jason
05:58 PM
Hmm, did you send a message Prajjval? I got a new message notification with your name, but I don’t see new messages above after my last question...
Prajjval
Photo of md5-1887cf6d03da176cbacb51c666d02d1b
Prajjval
05:58 PM
Hi Jason - I misspoke earlier. What I meant was uploading documents to the collection while faceting was taking a lot of time. I did realize that I was defining my datatype incorrectly. The issue is solved now, thanks!
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:00 PM
Ah ok. Typesense should show you a validation error if it receives the wrong data type. Did it just hang?