0

I am playing around with event sourcing using RavenDB.

I am storing all my events as documents in RavenDB then have a map/reduce index to generate the aggregates (similar to what is described here http://ayende.com/blog/4530/raven-event-sourcing).

However now I would like to index the aggregates that were the output of the map/reduce so I can query meaningful data in the database (e.g. finding accounts with negative balance). Unfortunately I can only seem to create indexes on documents which would make this whole approach unusable.

Is it possible to create an index on an index in RavenDB? Is there an alternative way to achieve the same result? Or am I better off to not have my aggregates as a map/reduce and just put them in as simple documents?

Alex
  • 3,245
  • 2
  • 19
  • 17

1 Answers1

0

You can do that using Scripted Index Results. See the docs http://ravendb.net/docs/article-page/2.5/csharp/server/extending/bundles/scripted-index-results

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • That would allow me to do something when the aggregate is created, still unsure what the something should be. Would you have to write the generated aggregate snapshots back out as a document to generate Indexes on them? or is there someway to directly tell an index to process the generated aggregate? – Alex Dec 15 '14 at 09:40
  • Yes, you write the result back to do document store. – Ayende Rahien Dec 16 '14 at 11:52
  • Seems a bit of a round about way of generating indexes on aggregates; creating a document to update an index to create a document to get an index. Ill accept as answer though as that seems to be the only way to index the generated aggregates. – Alex Dec 17 '14 at 08:16