Skip to content

Aggregate

Show:

The Aggregate endpoint groups documents in a bucket by a metadata field and returns the count for each distinct value. Use it to build facets, histograms, or category summaries.

Note: This endpoint uses collection in request bodies for backward compatibility. In newer Schift APIs the same concept is called a bucket.

Group and count documents by a metadata key.

HeaderRequiredDescription
AuthorizationYesBearer API key (Bearer $SCHIFT_API_KEY).
Content-TypeYesMust be application/json.
ParameterTypeRequiredDescription
collectionstringYesBucket name to aggregate. Kept as collection for compatibility.
group_bystringYesMetadata key to group by.
filter_keystringNoOptional metadata key to filter on before grouping.
filter_valuestringNoOptional value to match for the filter key.

Count documents by category:

Terminal window
curl -X POST https://api.schift.io/v1/aggregate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SCHIFT_API_KEY" \
-d '{
"collection": "product-docs",
"group_by": "category"
}'
FieldTypeDescription
groupsarrayList of groups with value and count.
groups[].valuestringThe grouped value.
groups[].countintegerNumber of items in this group.
totalintegerTotal count across all groups.
{
"groups": [
{
"value": "Getting Started",
"count": 12
},
{
"value": "API Reference",
"count": 28
},
{
"value": "Troubleshooting",
"count": 7
}
],
"total": 47
}

You can pre-filter documents before grouping by supplying filter_key and filter_value. Only documents whose metadata contains the matching value are included in the aggregation.

Terminal window
curl -X POST https://api.schift.io/v1/aggregate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SCHIFT_API_KEY" \
-d '{
"collection": "product-docs",
"group_by": "status",
"filter_key": "category",
"filter_value": "API Reference"
}'

Response:

{
"groups": [
{
"value": "published",
"count": 22
},
{
"value": "draft",
"count": 6
}
],
"total": 28
}
StatusMeaningExample response
402Query quota exceeded or not allowed.{"detail": {"allowed": false, ...}}
403Query quota unavailable for the current plan.{"detail": "Query quota unavailable. Upgrade your plan."}
404The specified collection or bucket was not found.{"detail": "Collection not found: product-docs"}
501The configured vector backend does not support aggregation.{"detail": "Aggregate not supported by backend: <BackendName>"}
VersionStatusNotes
v1DeprecatedCurrent endpoint. The collection parameter is retained for compatibility with legacy integrations.