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:
metric
aggregation - 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.bucket
aggregation - 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, ...) |
Avg aggregation
The Avg
aggregation makes it possible to calculate the average value for a field. The following SQL statement is executed in the background: AVG(price)
.
Count aggregation
The 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: COUNT(DISTINCT(manufacturerId))
.
Max aggregation
The max
aggregation allows you to determine the maximum value of a field. The following SQL statement is executed in the background: MAX(price)
.
Min aggregation
The min
aggregation makes it possible to determine the minimum value of a field. The following SQL statement is executed in the background: MIN(price)
Sum aggregation
The sum
aggregation makes it possible to determine the total of a field. The following SQL statement is executed in the background: SUM(price)
.PHPAPI
Stats aggregation
The stats
aggregation makes it possible to calculate several values at once for a field. This includes the previous max
, min
, avg
and sum
aggregation. 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 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 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 aggregation does not determine any result, it cannot be used alone. It is only used to further restrict the result of an aggregation in a criterion. Filters which 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
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. With the histogram aggregation one of the following date intervals can be given: minute
, hour
, day
, week
, month
, quarter
, year
, day
. This interval groups the result and calculates the corresponding count of hits.
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 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. *