Skip to content

Commit

Permalink
Merge pull request #35 from wgh000/patch-1
Browse files Browse the repository at this point in the history
Improve description of aggregates functions
  • Loading branch information
olegator77 committed Feb 4, 2019
2 parents 5a6e821 + 9a33956 commit a6b5b12
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,27 +419,29 @@ For make query to the composite index, pass []interface{} to `.WhereComposite` f

### Aggregations

Reindexer allows to do aggregation queries. Currently Average and Sum aggregations are supported. To support aggregation `Query` has method:
`Aggregate` should be called before Query execution - to ask reindexer calculate aggregation.
Reindexer allows to retrive aggregated results. Currently Average and Sum aggregations are supported.
In order to support aggregation, `Query` has method `Aggregate` that should be called before the `Query` execution: this will ask reindexer to calculate data aggregations.

To get aggregation results `Iterator` had method `AggResults`, it is available after query execution, and returns slice of reults.
To get aggregation results, `Iterator` has method `AggResults`: it is available after query execution and returns slice of results.

There are 3 aggregations availavle
There are 3 aggregations available

- `AggMax` - get maximum field value
- `AggMin` - get manimum field value
- `AggSum` - get sum field value
- `AggAvg` - get averatge field value
- `AggFacet` - get field facet value

Example code for aggregate `items` by `name`

```go

iterator := db.Query ("items").Aggregate ("name",reindexer.AggFacet).Exec ()
iterator := db.Query ("items").Aggregate ("name", reindexer.AggFacet).Exec ()

aggRes := iterator.AggResults()[0]

for facet := range aggRes.Facets {
fmt.Printf ("%s -> %d",facet.Value, facet.Count)
fmt.Printf ("%s -> %d", facet.Value, facet.Count)
}

```
Expand Down

0 comments on commit a6b5b12

Please sign in to comment.