Aggregations
Log in to add to favouritesPage last updated 28 October 2025
Aggregations allow you to group data by specific fields and return a count of entries matching each value, providing insights into data distribution and allowing refined searches.
Defining and Using Aggregations
Aggregations can be added to a search query using an aggregations object. This allows you to group results by a specific field and return a count of entries matching each value. Here's how to set up aggregations:
Example Aggregation Setup
{
"where": [
{ "field": "sys.versionStatus", "equalTo": "latest" }
],
"aggregations": {
"tags": {
"field": "entryTags",
"missing": "Untagged",
"size": 5
}
},
"pageIndex": 0,
"pageSize": 10
}- Aggregations Object: Add an
aggregationsobject alongside your normal search query.
The user defined name of the child object (e.g.,tags) determines how the results will appear in the response. - Field: Specify the field you want to group by using the
fieldattribute.
Limitation: Fields with a dataFormat oftaghave been specifically designed to retain their original casing in aggregation results. All other field types will return values in lowercase by default. - Missing Attribute: Use
missingto assign a value (e.g., "Untagged") to items that lack a value for the specified field. If omitted the missing count will not appear in the results. - Size: Define the number of groupings to return using the
sizeattribute. The default is10if not specified.
Examples
Example 1: Returning Entries Along with Aggregations
Endpoint
POST /api/delivery/projects/website/entries/search
Request Body
{
"where": [
{ "field": "sys.versionStatus", "equalTo": "latest" }
],
"aggregations": {
"tags": {
"missing": "Untagged",
"field": "entryTags",
"size": 20
}
},
"pageIndex": 0,
"pageSize": 10
}Explanation
- Retrieves entries and aggregations in the same response.
- Limits returned entries to the first 10 using
pageSize. - Aggregates data by the
entryTagsfield astags.- Labels missing values as "Untagged."
- Returns the top 20 tags.
Result Example
{
"pageIndex": 0,
"pageSize": 10,
"totalCount": 509,
"pageCount": 51,
"items": [
... Entry data ...
],
"aggregations": {
"tags": {
"Untagged": 500,
"Car": 7,
"Truck": 5,
"Motorbike": 2
}
}
}Example 2: Using multiple Aggregations with a where Query
Endpoint
POST /api/delivery/projects/website/entries/search
Request Body
{
"where": [
{ "field": "sys.versionStatus", "equalTo": "latest" }
],
"aggregations": {
"tags": {
"missing": "Untagged",
"field": "entryTags",
"size": 20
},
"another": {
"field": "myField",
"size": 5
}
},
"pageIndex": 0,
"pageSize": 0
}Explanation
- Filters entries to retrieve only the latest version.
- Aggregates data by the
entryTagsfield astags.- Labels missing values as "Untagged".
- Returns the top 20 tags.
- Aggregates data by the
myFieldfield asanother.- Returns the top 5 values.
- Suppresses entry results by setting
pageSizeto 0.
Result Example
{
"pageIndex": 0,
"pageSize": 0,
"totalCount": 509,
"pageCount": 0,
"items": [],
"aggregations": {
"tags": {
"Untagged": 500,
"Car": 7,
"Ferrari": 4,
"Toyota": 4
},
"another": {
"value1": 8,
"value3": 5,
"value2": 1
}
}
}Example 3: Using Aggregations with ZenQL
- Aggregates data by the
entryTagsfield astags.- Labels missing values as "Untagged".
- Returns the top 20 tags.
Endpoint
GET /api/delivery/projects/website/entries?zenql=sys.versionStatus=latest&aggregations={"tags":{"field":"entryTags"}}&pagesize=0
Explanation
- Filters entries using ZenQL to retrieve only the latest versions.
- Groups entries by the
entryTagsfield. - Omits entry details by setting
pagesize=0.
Result Example
{
"pageIndex": 0,
"pageSize": 0,
"totalCount": 509,
"pageCount": 0,
"items": [],
"aggregations": {
"tags": {
"Car": 10,
"Truck": 5,
"Motorbike": 2
}
}
}Example 4: Refining Searches with Aggregations
Request Body
{
"where": [
{ "field": "sys.versionStatus", "equalTo": "latest" },
{ "field": "entryTags", "equalTo": "car" },
{ "field": "entryTags", "equalTo": "red" }
],
"aggregations": {
"tags": {
"missing": "Untagged",
"field": "entryTags",
"size": 20
}
},
"pageIndex": 0,
"pageSize": 0
}Explanation
- Filters entries tagged with "car" and "red".
- Aggregates additional tags for refined filtering.
Result Example
{
"pageIndex": 0,
"pageSize": 0,
"totalCount": 509,
"pageCount": 0,
"items": [],
"aggregations": {
"tags": {
"Convertible": 3,
"SUV": 2
}
}
}Key Use Cases
- Understanding Data Distribution: Aggregations let you group data by specific fields, providing counts for each category (e.g., tags or statuses). This helps you quickly understand how data is distributed.
- Handling Missing Values:
Use the
missingproperty to group entries that lack a value for the specified field, ensuring such entries are included in the results. Note: "Untagged" cannot be used as an actual tag value. - Refining Searches: Aggregations reveal additional filtering options (e.g., related tags) that can guide further refinement of your searches. Start with broad queries and use aggregation results to drill down into specific subsets of data.