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: <authorization>' \
  --header 'Content-Type: application/json' \
  --header 'X-Namespace: <x-namespace>' \
  --data '
{
  "group_by": [
    {
      "field": "<string>",
      "alias": "category",
      "date_trunc": "day",
      "date_part": "hour"
    }
  ],
  "aggregations": [
    {
      "function": "count",
      "alias": "<string>",
      "field": "metadata.views",
      "distinct_field": "metadata.user_id"
    }
  ],
  "filters": {
    "metadata.status": "active"
  },
  "having": [
    {
      "field": "<string>",
      "operator": "<string>",
      "value": 100
    }
  ],
  "unwind": "blobs",
  "range_buckets": [
    {
      "field": "<string>",
      "boundaries": [
        123
      ],
      "default_bucket": "other"
    }
  ],
  "sort_by": "total_count",
  "sort_direction": "desc",
  "limit": 10
}
'
{
  "results": [
    {
      "group": {},
      "metrics": {}
    }
  ],
  "total_groups": 123,
  "query_info": {}
}

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.

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'

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 array 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 array length: 1
filters
Filters · object

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

Example:
{ "metadata.status": "active" }
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.

Example:

"blobs"

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.

Example:

"total_count"

sort_direction
string
default:desc

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

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
Example:

10

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
Query Info · object

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