ElasticGraph Query API: Aggregations
Try these example queries by visiting the GraphiQL UI after booting locally.
Copied!
$ curl -s https://block.github.io/elasticgraph/dc.yml | docker compose -f - up --pull always
ElasticGraph offers a powerful aggregations API. Each indexed type gets a corresponding *Aggregations
field.
Here’s a complete example:
Copied!
query BluegrassArtistAggregations($cursor: Cursor) {
artistAggregations(
first: 10
after: $cursor
filter: {genres: {anySatisfy: {equalToAnyOf: [BLUEGRASS]}}}
) {
pageInfo {
hasNextPage
endCursor
}
nodes {
groupedBy {
bio { yearFormed }
}
aggregatedValues {
lifetimeSales {
approximateAvg
exactMin
exactMax
}
}
count
subAggregations {
albums(
first: 3
filter: {tracks: {count: {gt: 10}}}
) {
nodes {
countDetail { approximateValue }
}
}
}
}
}
}
Aggregation fields support filtering and pagination
but do not support client-specified sorting1. Under an aggregations field, each node
represents a grouping of documents. When groupedBy
fields have been requested,
each node represents the grouping of documents that have the groupedBy
values. When no groupedBy
fields have been requested,
a single node will be returned containing a grouping for all documents matched by the filter.
Aggregation nodes in turn offer 4 different aggregation features: