Aggregations
Aggregations represent similar fields in multiple documents allowing you to filter results accordingly. They allow users to analyze already searched and returned data and extract statistics from the aggregated data. For facilitation purposes, there are multiple APIs present that can be called to create, update, or manage aggregations. The purpose of this document is to understand the functionality behind them.
If there are no specified aggregations at the time of query, default aggregations are triggered. The user doesn't need to define their priority. Users can always set a basic default aggregation with the highest priority and no condition. Later, other default aggregations with lower priority can be defined but with a condition that overrules the basic one. This is because a single default aggregation can be applied on the query and only on the condition that no aggregation was applied before.
Note: The difference between aggregation appenders and default aggregations is that only 1 default aggregation can be applied at a time. On the other hand, multiple aggregation appenders can be applied simultaneously. It is also important to remember that default aggregations require no NoChannel Search aggregation to be applied before.
This endpoint allows users to attach default aggregations with a query pipeline. Users can attach one default aggregation with multiple query pipelines. The API call to attach the default aggregation is:
POST https://api.upstartcommerce.com/v1/search/default-aggregation/attach/resource-id/to/querypipeline
Notice that the default aggregations' id is added before 'to' and after it, the query pipeline id is defined.
The detach function allows users to remove a particular default aggregation from the query pipeline. The API call to detach the default aggregation is:
POST https://api.upstartcommerce.com/v1/search/default-aggregation/detach/resource_id/from/querypipeline
Notice that the id of the default aggregation is added before 'from' and after it, the query pipeline id is defined.
There are multiple types of aggregations. Apart from the aggregations offered by OpenSearch, NoChannel Search provides its users with different aggregations to facilitate the searching process.
Managed aggregations are aggregations that are given some properties such as a name through which they can be referred. This facilitates the client at the time of performing queries because of the stable identifiers that are associated with them. All the aggregations are present in the same place making it easier to manage them all from a single place. Managed Aggregations are categorized based on terms or ranges. To understand their functionality better refer to the OpenSearch documentation.
AggregationRef are the aggregations that are used to point or refer towards an existing managed or aggregation set. This is a NoChannel Search specific aggregation. To understand them better, consider the following code block:
In the example above, in the aggregations block, once the type is defined, a reference "ref" pointer is specified to a pre-existing managed aggregation.
Multiple aggregations grouped by a set of properties such as brand names, sizes, and other similar fields are called Aggregation sets. It is important to remember that the resulting sets are also aggregations. This is another NoChannel Search specific aggregation.
For example, a user can create an aggregation set for "Fruits" with individual aggregations such as "season: summer, winter", "price-range: $1, $100", and so on. Any time a query is made regarding fruits, the generated result will be retrieved from the aggregation set.
Continuing the example used in Managed Aggregation consider the following code block for the creation of an aggregation set:
The API Call to create an aggregation set is:
POST https://api.upstartcommerce.com/v1/search/aggregation
The unique field is:
- refs: This is an array that includes multiple managed aggregations that are to become a part of the aggregation set. In the example above, those are brandName_term and price-facet.
Through this type of aggregation, aggregations are appended if a certain condition is satisfied. This means that if a particular term is searched in the query, a specific aggregation will be appended to the search results. To understand the functionality better, go through the documentation of Query Rules.