Ashutosh Thakur
05/11/2025, 8:39 AMgroup_by
functionality in Typesense to group documents by a specific field (e.g. supplier_id
). I wanted to know if there’s currently a way to perform aggregation operations like SUM
, AVG
, MIN
, or COUNT
on grouped fields directly within Typesense, similar to how SQL or Elasticsearch aggregations work?
For example:
• Group all documents by supplier_id
• Then compute the SUM
or AVG
of the price
field per group
• And return that in the search result itself
Is this kind of aggregation supported?
If not, is it something that’s on the roadmap or are there any suggested workarounds apart from post-processing on the client/server side?
Thanks in advance!
cc. @Sahil Rally @Atishay JainÓscar Vicente
05/11/2025, 10:20 AMÓscar Vicente
05/11/2025, 10:20 AMAshutosh Thakur
05/11/2025, 12:51 PMAshutosh Thakur
05/11/2025, 12:51 PMÓscar Vicente
05/11/2025, 12:58 PMAshutosh Thakur
05/11/2025, 1:15 PMÓscar Vicente
05/11/2025, 1:15 PMSahil Rally
05/11/2025, 7:04 PMÓscar Vicente
05/11/2025, 7:05 PMKishore Nallan
05/11/2025, 7:06 PMSahil Rally
05/11/2025, 7:08 PMÓscar Vicente
05/11/2025, 7:09 PMSahil Rally
05/11/2025, 7:10 PMSahil Rally
05/11/2025, 7:10 PMSahil Rally
05/11/2025, 7:15 PMAtishay Jain
05/11/2025, 8:14 PMAtishay Jain
05/11/2025, 8:16 PM{
"facet_counts": [
{
"counts": [
{
"count": 2,
"highlighted": "1",
"value": "1"
},
{
"count": 2,
"highlighted": "2",
"value": "2"
},
],
"field_name": "quantity",
"sampled": false,
"stats": {
"avg": 2,
"max": 2,
"min": 1,
"sum": 8,
"total_values": 4
}
}
],
"found": 2,
"found_docs": 4,
"grouped_hits": [
{
"found": 2,
"group_key": [
"S1"
],
"hits": [
{
"document": {
"quantity": 1,
"supplierId": "S1"
},
"highlight": {},
"highlights": []
},
{
"document": {
"quantity": 2,
"supplierId": "S1"
},
"highlight": {},
"highlights": []
},
]
},
{
"found": 2,
"group_key": [
"S2"
],
"hits": [
{
"document": {
"quantity": 1,
"supplierId": "S2"
},
"highlight": {},
"highlights": []
},
{
"document": {
"quantity": 2,
"supplierId": "S2"
},
"highlight": {},
"highlights": []
}
]
}
]
"out_of": 4,
"page": 1,
"request_params": {
"collection_name": "supplierinventories",
"first_q": "",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 63
}
In the above response as we can see the stats has sum as 8 which is the sum of quantity across all hits but we want sum per group which would be like 3 and 3.Ashutosh Thakur
05/11/2025, 8:17 PMAtishay Jain
05/12/2025, 7:48 AMKishore Nallan
05/12/2025, 7:48 AMKishore Nallan
05/12/2025, 7:50 AMKishore Nallan
05/12/2025, 7:50 AMSahil Rally
05/12/2025, 7:51 AMKishore Nallan
05/12/2025, 7:52 AMSahil Rally
05/12/2025, 7:52 AMSahil Rally
05/12/2025, 7:57 AMKishore Nallan
05/12/2025, 8:06 AMSahil Rally
05/12/2025, 10:28 AM