-
Group by: partition or group data based on specified properties. For instance, to see the average temperature for equipment, you can group by the
equipmentproperty. - Aggregation functions: compute metrics on the grouped data. This includes calculating sums, averages, minimums, maximums, counts, and histograms.
- Filters and sorting: like the search endpoint, the aggregation endpoint supports filtering and sorting. This allows you to refine your data set before performing aggregations.
Recommendations
- Combine filters and aggregations: to minimize the volume of data to process, always apply filters before running aggregations.
- Use groupBy efficiently: restrict grouping to properties that are meaningful for your analysis. Excessive grouping can make results difficult to interpret and reduce performance.
- Understand tokenization for text queries: when searching for text, refer to the search endpoint’s tokenization rules.
- Plan around indexing delays: because of indexing delays, it may take a few seconds for new or updated data to be available for aggregation.
Example aggregation request
The aggregation request below groups byequipment and computes an average of the temperature property.
Example aggregation request
view: defines which view the query will read from. Required.aggregates: lists one or more aggregation operations. Maximum five operations in a single request.groupBy: is an array of property names used for grouping.queryandproperties: combine to perform text-based matching on the specified properties (name,description).filter: restricts data before aggregation. Only results withtemperaturebetween 15 and 25 are included.
Aggregating a single type
The examples below show different aggregations for a type called Company with these properties:| id | name | industry | revenue | head_count |
|---|---|---|---|---|
| 2001c18… | Ryan and Friesen and Sons | Internet | 80734000 | 5 |
| fe8bf42… | Pfannerstill Inc | Biotechnology | 37038000 | 50 |
| 6dc069… | Boyer and Kohler Group | Public Relations and Communications | 21598000 | 1 |
| f23a8a… | Mohr Group | Fund-Raising | 7440000 | 56 |
| d346e0… | Veum LLC | Real Estate | 5224000 | 10 |
Average head_count across all companies
Calculate the average head_count across every company in the dataset.
Request
Response
Average head_count grouped by industry
Group companies by industry and compute the average head_count for each distinct industry value.
Request
Response
Histogram aggregation
Use thehistogram function to divide a numeric property (head_count) into buckets. Below, each bucket has a width of 10. The result shows how many companies fall into each bucket, grouped by industry.
Request
Response (abbreviated)
Text search within an aggregation
Similar to the search endpoint, you can combine text-based queries with aggregations. You can also use theoperator field to control whether all ("AND") or any ("OR") query terms must match.
See Search features documentation for details.
This example computes the average head_count for companies where name starts with “Inc”.