Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10205

Group and select the top K elements in each group

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Environment:
      All

      Description

      I would like the ability in the aggregation framework to group and select the top K elements in each group.

      Here is an example:

      Let's say I have documents with the following structure:

      { "_id":..., "Group": 1, "Value": 4 } { "_id":..., "Group": 2, "Value": 8 } { "_id":..., "Group": 1, "Value": 10 }

      Given X, Y and K, I would like to be able to use the aggregation framework to do the following:

      • Select all documents with the "Group" property between X and Y
      • Group by the "Group" property
      • In each group: pick only the K documents with the largest "Value" property

      Because K will be much smaller than the size of the collection itself, I would like to be able to do that in a way that is memory efficient.

      There is a new feature in 2.4 where we can efficiently sort then limit with the aggregation framework. This is basically the same thing, working on groups.

      I have no preference on which operator should enable this scenario, as long as it is possible to achieve what I just described.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              flavien Flavien
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: