You are currently browsing legacy 2.5 version of documentation. Click here to switch to the newest 5.1 version.
In order to explain this feature, let us start with an example. First we are creating the a simple index. The one thing to notice is that we are explicitly setting the Sort
mode for Total to be
Now we are going to Query > Reporting:
And then we can start issue reporting queries:
This is the equivalent of doing:
select EmployeeID, sum(tot.Total) Total from Orders o join ( select sum((Quantity * UnitPrice) * (1- Discount)) Total, OrderId from [Order Details] group by OrderID ) tot on o.OrderID = tot.OrderID where o.CustomerID = @CustomerId group by EmployeeID
The nice thing about this, and what makes this feature different from standard map/reduce, is that you can filter the input data into the aggregation. In code, this would look something like this:
session.Query<Order>("Orders/Total") .Where(x => x.Company == "companies/1") .AggregateBy(x => x.Employee) .SumOn(x => x.Total) .ToList();
This reporting availability takes advantage of the dynamic aggregation feature.