Fanout indexes and recursive queries

84 views
Skip to first unread message

Steven Roberts

unread,
Dec 4, 2017, 7:38:18 PM12/4/17
to RavenDB - 2nd generation document database
Hello,

I have a model with a deeply nested structure that I want to index.  The structure can be infinitely nested but practically probably no more than 2 or 3 levels deep.  Each level though could have many items at that level.  I need to index these items in a flattened structure.  I'm doing this now but I'm getting an error about too many index entries..

ndex 'WorkplanActivityIndex' has already produced 51 map results for a source document 'ProjectWorkplans/12', while the allowed max number of outputs is 50 per one document. Please verify this index definition and consider a re-design of your entities or index


How can I re-design my index to better accommodate this scenario?  Here's my current index.
            Map = workplans => from workplan in workplans
                let project = LoadDocument<Project>(workplan.ProjectId)
                let log = LoadDocument<ProjectHourLog>(project.HoursLog.Id)
                let activities = Recurse(workplan, pw => (IEnumerable<WorkplanActivity>) pw.ChildActivities)
                from activity in activities
                from user in activity.Assignees
                select new
                {
                    ProjectId = project.Id,
                    ProjectName = project.Descriptor.Name,
                    ProjectStatus = project.Status.State.ToString(),
                    WorkplanId = workplan.Id,
                    ActivityId = activity.Id,
                    ActivityName = activity.Descriptor.Name,
                    ActivityStatus = activity.Status.Name.ToString(),
                    user.UserId,
                    
                };


I'm looking for some insight into how to write this better.

Oren Eini (Ayende Rahien)

unread,
Dec 5, 2017, 2:41:32 AM12/5/17
to ravendb
Do you need to index each of them separately?
What about:

  Map = workplans => from workplan in workplans
                let project = LoadDocument<Project>(workplan.ProjectId)
                let log = LoadDocument<ProjectHourLog>(project.HoursLog.Id)
                let activities = Recurse(workplan, pw => (IEnumerable<WorkplanActivity>) pw.ChildActivities)
                let users = activities.SelectMany(x=>x.Assignees)
                select new
                {
                    ProjectId = project.Id,
                    ProjectName = project.Descriptor.Name,
                    ProjectStatus = project.Status.State.ToString(),
                    WorkplanId = workplan.Id,
                    ActivityId = activity.Id,
                    ActivityName = activity.Descriptor.Name,
                    ActivityStatus = activity.Status.Name.ToString(),
                    UserId = users.Select(x=>x.UserId),
                    
                };


Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Roberts

unread,
Dec 5, 2017, 1:21:19 PM12/5/17
to RavenDB - 2nd generation document database
So this will give me a single document per workplan but flattened activities as a collection in the document?  Am I visualizing that correctly?
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Steven Roberts

unread,
Dec 5, 2017, 1:23:11 PM12/5/17
to RavenDB - 2nd generation document database
oh wait, you are doing the SelectMany against the user collection.  Does that mean it's the Users not the activities that are causing the error?

Oren Eini (Ayende Rahien)

unread,
Dec 6, 2017, 3:15:25 AM12/6/17
to ravendb
Yes
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Dec 6, 2017, 3:15:53 AM12/6/17
to ravendb
You have two fanout sources:

from activity in activities
                from user in activity.Assignees

My change eliminated both
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages