Aggregations can be requested when querying items. They are used to calculate summarized views and statistics about the data in a search results. This allows you to build data drill-downs along the structured part of items as well as visualizations over time or other data dimensions.
Table of Contents
Table of Contents |
---|
outline | true |
---|
exclude | Table of Contents |
---|
|
Specification
The request format is an url encoded JSON object of the following format:
...
Code Block |
---|
|
"language": {
"fields": "language"
} |
This can also be shortened, as the label can also serve as the field:
Set number of results
By default 10 results are returned for each fields. This can be changed by setting the size parameter. For example to retrieve the top 3 languages from the result set:
Code Block |
---|
|
"language": {
"size": 3
} |
Select multiple fields
To return the result counts for all values in multiple fields, simply list the fields:
Code Block |
---|
|
"multi": {
"fields": ["provider", "language"]
} |
Group by multiple fields
It's possible to add nested dimensions in an aggregation. The example below groups the result first by language and then within each language by provider:
Code Block |
---|
|
"language": {
"aggregate": {"fields": "provider"}
} |
Group by date
The histogram aggregation method is recommended for dates, because it groups values by hour, day, week, etc.
To count the results for \item's creation dates, use the following aggregation:
Code Block |
---|
|
"$item_created_at": {
"method": "histogram"
} |
This can again be nested, to for example aggregate the languages of items over time:
Code Block |
---|
|
"$item_created_at": {
"method": "histogram",
"aggregation": {
"fields": ["language"],
}
} |