Open
Description
This is a proposed API for aggregations.
The aggregation pipeline is very suitable for a builder/fluent style API. It basically includes the following elements, repeating and transforming the pipeline:
- The base filter query (non repeating)
- Load - load properties from the document (if they are not in the sortables)
- Group by (with its reducers)
- Sort by
- Apply expression on values
- Limit
These are chained repeatably to transform the pipeline. So here's what I have in mind:
# query can be a string or a structured query object
req = AggregateRequest(query)
.load('@foo', '@bar')
.group_by(('@foo', '@bar'),
#reducers
count().as('total'),
count_distinct('@bar').as('num_bars'),
# alternative proposal
num_bars = count_distinct('@bar')
)
.apply("sqrt(@foo/@num_bars)", as='sqr')
.sort_by(Sort.desc('@sqr'), Sort.asc('@other'), max_results = 100)
.limit(0, 10)
resp = client.aggregate(req)
Metadata
Metadata
Assignees
Labels
No labels