Skip to main content
POST
/
v1
/
buckets
/
{bucket_identifier}
/
objects
/
aggregate
Aggregate Objects
curl --request POST \
  --url https://api.mixpeek.com/v1/buckets/{bucket_identifier}/objects/aggregate \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'X-Namespace: <x-namespace>' \
  --data '{
  "aggregations": [
    {
      "alias": "total",
      "function": "count"
    }
  ],
  "description": "Count objects by status",
  "group_by": [
    {
      "alias": "status",
      "field": "status"
    }
  ],
  "sort_by": "total",
  "sort_direction": "desc"
}'
{
  "query_info": {
    "execution_time_ms": 45,
    "pipeline_stages": 5
  },
  "results": [
    {
      "group": {
        "status": "completed"
      },
      "metrics": {
        "total": 1523
      }
    },
    {
      "group": {
        "status": "pending"
      },
      "metrics": {
        "total": 87
      }
    }
  ],
  "total_groups": 2
}

Authorizations

Authorization
string
header
required

Bearer token authentication using your API key. Format: 'Bearer your_api_key'. To get an API key, create an account at mixpeek.com/start and generate a key in your account settings.

Headers

Authorization
string
required

REQUIRED: Bearer token authentication using your API key. Format: 'Bearer sk_xxxxxxxxxxxxx'. You can create API keys in the Mixpeek dashboard under Organization Settings.

Examples:

"Bearer sk_live_abc123def456"

"Bearer sk_test_xyz789"

X-Namespace
string
required

REQUIRED: Namespace identifier for scoping this request. All resources (collections, buckets, taxonomies, etc.) are scoped to a namespace. You can provide either the namespace name or namespace ID. Format: ns_xxxxxxxxxxxxx (ID) or a custom name like 'my-namespace'

Examples:

"ns_abc123def456"

"production"

"my-namespace"

Path Parameters

bucket_identifier
string
required

The unique identifier of the bucket.

Body

application/json

Aggregation configuration specifying grouping, metrics, and filters.

group_by
GroupByField · object[]
required

Fields to group results by. REQUIRED, at least one field. Can include field transformations (date_trunc, date_part). Results will have one row per unique combination of group_by values.

Minimum length: 1
aggregations
AggregationOperation · object[]
required

Aggregation operations to perform. REQUIRED, at least one operation. Each operation produces a calculated field in results. Can combine multiple functions (COUNT, SUM, AVG, etc.).

Minimum length: 1
filters
object | null

Pre-aggregation filters to apply to source data. OPTIONAL, filters data before grouping. Uses same syntax as standard query filters. Applied before GROUP BY.

Examples:
{ "metadata.status": "active" }
{
"created_at": { "$gte": "2024-01-01" },
"metadata.type": "video"
}
having
HavingCondition · object[] | null

Post-aggregation filters to apply to results. OPTIONAL, filters groups after aggregation. Uses aggregation aliases as field names. Applied after GROUP BY and aggregation calculations.

unwind
string | null

Array field to unwind before aggregation. OPTIONAL, creates one document per array element. Useful for aggregating over array contents. Example: 'blobs' to analyze each blob separately.

Examples:

"blobs"

"metadata.tags"

"metadata.categories"

range_buckets
RangeBucket · object[] | null

Range-based bucketing for numeric fields. OPTIONAL, creates histogram-style buckets. Groups numeric values into defined ranges. Applied during grouping stage.

sort_by
string | null

Field to sort results by. OPTIONAL, can be group_by field or aggregation alias. Defaults to no specific order. Use with sort_direction to control order.

Examples:

"total_count"

"avg_duration"

"category"

sort_direction
string
default:desc

Sort direction. OPTIONAL, defaults to 'desc' (descending). Valid values: 'asc' (ascending), 'desc' (descending). Used with sort_by field.

Examples:

"asc"

"desc"

limit
integer | null

Maximum number of results to return. OPTIONAL, no limit if not specified. Applied after sorting. Useful for 'top N' queries.

Required range: x > 0
Examples:

10

50

100

Response

Successful Response

Response containing object aggregation results.

Returns aggregated statistics grouped by specified fields.

results
AggregationResult · object[]
required

List of aggregation results, one per group.

total_groups
integer
required

Total number of unique groups returned.

query_info
object

Additional information about the query execution. May include pipeline stages, execution time, etc.