Skip to content

Aggregations Reference

You are viewing the next version (v6.7) of the documentation.
Click here to switch to the stable version (v6.6), or use the version switcher on the left to navigate between versions.

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.
NameTypeDescription
avgmetricAverage of all numeric values for the specified field
countmetricNumber of records for the specified field
maxmetricMaximum value for the specified field
minmetricMinimal value for the specified field
statsmetricStats overall numeric values for the specified field
summetricSum of all numeric values for the specified field
entitybucketGroups the result for each value of the provided field and fetches the entities for this field
filterbucketAllows to filter the aggregation result
termsbucketGroups the result for each value of the provided field and fetches the count of affected documents
histogrambucketGroups the result for each value of the provided field and fetches the count of affected documents. Although allows to provide date interval (day, month, ...)
rangebucketGroups 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 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 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

The 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

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.

Range aggregations

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:

  • from will be compared with greater than or equal to
  • to will 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 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. *