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.
|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 makes it possible to calculate the average value for a field. The following SQL statement is executed in the background:
count aggregation makes it possible to determine the number of entries for a field that are filled with a value. The following SQL statement is executed in the background:
max aggregation allows you to determine the maximum value of a field. The following SQL statement is executed in the background:
min aggregation makes it possible to determine the minimum value of a field. The following SQL statement is executed in the background:
stats aggregation makes it possible to calculate several values at once for a field. This includes the previous
sum aggregation. The following SQL statement is executed in the background:
SELECT MAX(price), MIN(price), AVG(price), SUM(price).
terms aggregation belongs to the bucket aggregations. This allows you to determine the values of a field. The result contains each value once and how often this value occurs in the result. 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 sorted
aggregation- 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 belongs to the bucket aggregations. Unlike all other aggregations, this aggregation does not determine any result. It can't be used alone. It is only used to further 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 result of the search.
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.
The histogram aggregation is used as soon as the data to be determined refers to a date field. With the histogram aggregation, one of the following date intervals can be given:
day. This interval groups the result and calculates the corresponding count of hits.
Allows to aggregate data on a predefined range of values for more flexibility in the DAL - for example, it provides faceted filters on a predefined range.
Bound are computed in SQL as in the Elasticsearch native range aggregation:
fromwill be compared with greater than or equal to
towill be compared with lower than
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 it together with the count. 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 Euro. *