Aggregations Reference
Aggregations allow you to determine further information about the overall result in addition to the actual search results. These include totals, unique values, or the average of a field.
The DAL knows two types of aggregations:
metricaggregation - This type of aggregation applies a mathematical formula to a field. A metric aggregation always has a calculated result. These are aggregations to calculate sums or maximum values.bucketaggregation - With this type of aggregation, a list of keys is determined. Further aggregations can then be determined for each key.
| Name | Type | Description |
|---|---|---|
| avg | metric | Average of all numeric values for the specified field |
| count | metric | Number of records for the specified field |
| max | metric | Maximum value for the specified field |
| min | metric | Minimal value for the specified field |
| stats | metric | Stats overall numeric values for the specified field |
| sum | metric | Sum of all numeric values for the specified field |
| entity | bucket | Groups the result for each value of the provided field and fetches the entities for this field |
| filter | bucket | Allows to filter the aggregation result |
| terms | bucket | Groups the result for each value of the provided field and fetches the count of affected documents |
| histogram | bucket | Groups the result for each value of the provided field and fetches the count of affected documents. Although allows to provide date interval (day, month, ...) |
| range | bucket | Groups the result for each defined set of ranges into each bucket - bucket of numerical data and a count of items/documents for each bucket |
Avg aggregation
The Avg aggregation calculates the average value for a field. The following SQL statement is executed in the background: AVG(price).
Count aggregation
The count aggregation allows you to determine the number of entries in a field that contain a value. The following SQL statement is executed in the background: COUNT(DISTINCT(manufacturerId)).
Max aggregation
The max aggregation returns the maximum value of a field. The following SQL statement is executed in the background: MAX(price).
Min aggregation
The min aggregation returns the minimum value of a field. The following SQL statement is executed in the background: MIN(price).
Sum aggregation
The sum aggregation allows you to compute the total of a field. The following SQL statement is executed in the background: SUM(price).
Stats aggregation
The stats aggregation allows you to calculate multiple values for a field at once. This includes the previous max, min, avg, and sum aggregations. The following SQL statement is executed in the background: SELECT MAX(price), MIN(price), AVG(price), SUM(price).
Terms aggregation
The terms aggregation belongs to the bucket aggregations. This allows you to determine the values of a field. The result contains each value once, along with how often it occurs. The terms aggregation also supports the following parameters:
limit- Defines a maximum number of entries to be returned (default: zero)sort- Defines the order of the entries. By default, the following is not sortedaggregation- Enables you to calculate further aggregations for each key
The following SQL statement is executed in the background: SELECT DISTINCT(manufacturerId) as key, COUNT(manufacturerId) as count.
Filter aggregation
The filter aggregation belongs to the bucket aggregations. Unlike all other aggregations, this one does not produce a result. It can't be used alone. It is used only further to restrict the result of an aggregation in a criterion. Filters defined inside the filter property of this aggregation type are only used when calculating this aggregation. The filters have no effect on other aggregations or on the search results.
Entity aggregation
The entity aggregation is similar to the terms aggregation. It belongs to the bucket aggregations. As with terms aggregation, all unique values are determined for a field. The aggregation then uses the determined keys to load the defined entity. The keys are used here as IDs.
Histogram aggregation
The histogram aggregation is used as soon as the data to be determined refers to a date field. For histogram aggregation, one of the following date intervals can be specified: minute, hour, day, week, month, quarter, year, day. This interval groups the results and calculates the corresponding count of hits.
Range aggregations
Allows for aggregation of data on a predefined range of values for more flexibility in the DAL - for example, it provides faceted filters on a predefined range.
fromwill be compared with greater than or equal totowill be compared with lower than
Nesting aggregations
A metric aggregation calculates the value for a specific field. This can be a total or, for example, a minimum or maximum value of the field. Bucket aggregations are different. This determines how often a value occurs in a search result and returns the count along with it. The special thing about bucket aggregation is that it can contain further aggregations. This allows the API to perform complex queries, like, for example:
- Calculate the number of manufacturers per category that have a price over 500 euros. *