Search & metadata
Typesense faceting
Count values in a Typesense result set.
Faceting gives you total counts for any field in your results. It helps you build filters and understand how your data is grouped. You can:
- Count transactions per currency
- See how many transactions are in each status
- Group balances by ledger or identity
- Break transactions into date or amount ranges
Quick start
Here’s a basic faceting request that shows the total counts for the status and currency fields:
curl -X POST "http://localhost:5001/search/transactions" \
-H "X-blnk-key: <api-key>" \
-H "Content-Type: application/json" \
-d '{
"q": "*",
"facet_by": "status,currency"
}'const response = await blnk.Search.search(
{ q: '*', facet_by: 'status,currency' },
'transactions',
);results, _, _ := client.Search.SearchDocument(
blnkgo.SearchParams{Q: "*", FacetBy: "status,currency"},
blnkgo.Transactions,
)response = blnk.search.search(
{"q": "*", "facet_by": "status,currency"},
"transactions",
)ApiResponse<JsonNode> response = blnk.search().search(
SearchParams.create()
.q("*")
.facetBy("status,currency"),
"transactions");{
"facet_counts": [
{
"counts": [
{
"count": 1000,
"highlighted": "APPLIED",
"value": "APPLIED"
},
{
"count": 1500,
"highlighted": "INFLIGHT",
"value": "INFLIGHT"
}
{
"count": 500,
"highlighted": "REJECTED",
"value": "REJECTED"
}
],
"field_name": "status",
"stats": {
"total_values": 1
}
},
{
"counts": [
{
"count": 876,
"highlighted": "GBP",
"value": "GBP"
},
{
"count": 821,
"highlighted": "EUR",
"value": "EUR"
},
{
"count": 803,
"highlighted": "USD",
"value": "USD"
}
],
"field_name": "currency",
"stats": {
"total_values": 3
}
}
]
}
| Field | Description |
|---|---|
field_name | The field being faceted. |
value | A unique value found in that field. |
count | Number of documents that have this value. |
counts | The full list of values and their counts. |
total_values | How many unique values exist for this field. |
Combining faceting with filters
Faceting becomes more powerful when combined with filters. You can facet on one field while filtering on others to analyze specific subsets of your data.
curl -X POST "http://localhost:5001/search/transactions" \
-H "X-blnk-key: <api-key>" \
-H "Content-Type: application/json" \
-d '{
"q": "*",
"filter_by": "currency:=USD",
"facet_by": "status"
}'const response = await blnk.Search.search(
{ q: '*', filter_by: 'currency:=USD', facet_by: 'status' },
'transactions',
);results, _, _ := client.Search.SearchDocument(
blnkgo.SearchParams{
Q: "*",
FilterBy: "currency:=USD",
FacetBy: "status",
},
blnkgo.Transactions,
)response = blnk.search.search(
{"q": "*", "filter_by": "currency:=USD", "facet_by": "status"},
"transactions",
)ApiResponse<JsonNode> response = blnk.search().search(
SearchParams.create()
.q("*")
.filterBy("currency:=USD")
.facetBy("status"),
"transactions");curl -X POST "http://localhost:5001/search/balances" \
-H "X-blnk-key: <api-key>" \
-H "Content-Type: application/json" \
-d '{
"q": "*",
"filter_by": "identity_id:=idt_28f25ef6-2e0d-4fa6-891c-37fc409d654e",
"facet_by": "currency"
}'const response = await blnk.Search.search(
{
q: '*',
filter_by: 'identity_id:=idt_28f25ef6-2e0d-4fa6-891c-37fc409d654e',
facet_by: 'currency',
},
'balances',
);results, _, _ := client.Search.SearchDocument(
blnkgo.SearchParams{
Q: "*",
FilterBy: "identity_id:=idt_28f25ef6-2e0d-4fa6-891c-37fc409d654e",
FacetBy: "currency",
},
blnkgo.Balances,
)response = blnk.search.search(
{
"q": "*",
"filter_by": "identity_id:=idt_28f25ef6-2e0d-4fa6-891c-37fc409d654e",
"facet_by": "currency",
},
"balances",
)ApiResponse<JsonNode> response = blnk.search().search(
SearchParams.create()
.q("*")
.filterBy("identity_id:=idt_28f25ef6-2e0d-4fa6-891c-37fc409d654e")
.facetBy("currency"),
"balances");The example above allows you to answer questions like:
- “Of all my USD transactions, how many are in each status?”
- “For this specific customer, how many balances do they have in each currency?""
Faceting on metadata fields
You can also facet on metadata objects.
curl -X POST "http://localhost:5001/search/transactions" \
-H "X-blnk-key: <api-key>" \
-H "Content-Type: application/json" \
-d '{
"q": "*",
"facet_by": "meta_data.transaction_type,meta_data.payment_method"
}'const response = await blnk.Search.search(
{
q: '*',
facet_by: 'meta_data.transaction_type,meta_data.payment_method',
},
'transactions',
);results, _, _ := client.Search.SearchDocument(
blnkgo.SearchParams{
Q: "*",
FacetBy: "meta_data.transaction_type,meta_data.payment_method",
},
blnkgo.Transactions,
)response = blnk.search.search(
{
"q": "*",
"facet_by": "meta_data.transaction_type,meta_data.payment_method",
},
"transactions",
)ApiResponse<JsonNode> response = blnk.search().search(
SearchParams.create()
.q("*")
.facetBy("meta_data.transaction_type,meta_data.payment_method"),
"transactions");