あなたが求めているのは、レポートの典型的なケースです。これは、RavenDB があまり適していないことの 1 つです ( http://ravendb.net/docs/server/bundles/index-replication )。あなたの質問は、SQL Server Analysis Services のキューブの構造に似ています。

この場合の問題は、日付範囲です。範囲が固定されている場合、たとえば月ごとに知りたい場合は、インデックスでこれを行うことができますが、範囲がアドホックである場合、Raven ではインデックスを使用してこれを行うことはできないと思います。グループ化クライアント側を実行する必要があり、大量のドキュメントを取得する必要があるため (Raven のデフォルトの 128 よりもはるかに多い)、クエリ。
ただし、誰かが日付範囲を省略したインデックスで複数のグループを例として検索している場合は、結果がユーザー ID、場所、およびイベントの種類によってグループ化されるインデックスの実装に従うことが解決策になる可能性があります。
public class Index : AbstractIndexCreationTask<Index.Result>
{
public class Result
{
public string UserId { get; set; }
public string Location { get; set; }
public string EventType { get; set; }
public int Count { get; set; }
}
public Index()
{
Map = events => from e in events
select new Result
{
UserId = e.UserId,
Location = e.Location,
EventType = e.EventType,
Count = 1
};
Reduce = results => from result in results
group result by new { result.UserId, result.Location, result.EventType }
into g
select new Result
{
UserId = g.Key.UserId,
Location = g.Key.Location,
EventType = g.Key.EventType,
Count = g.Sum(x => x.Count)
};
}
}
これにより、この結果が得られます
UserId | Location | EventType | Count
-------------------------------------------
1 | X | A | 2
1 | X | B | 4
1 | Y | A | 22
1 | Y | B | 6
2 | X | A | 7
2 | X | B | 3
2 | Y | A | 9
2 | Y | B | 16
その後、そのインデックスに対してクエリを実行し、クエリの結果に対して追加のグループ化を行うことができます。