Limit results per page per field

Hello

I have a case when I need to get only one or two documents per page that have the same field value
I can use collapse for that but the problem I don't want to ignore other documents in the next pages,

So suppose documents are like this:

    [
        {
            "id": 1,
            "user_id": 1
        },
        {
            "id": 2,
            "user_id": 1
        },
        {
            "id": 3,
            "user_id": 1
        },
        {
            "id": 4,
            "user_id": 1
        },
        {
            "id": 5,
            "user_id": 2
        },
        {
            "id": 6,
            "user_id": 2
        },
        {
            "id": 7,
            "user_id": 2
        },
        {
            "id": 8,
            "user_id": 3
        },
        {
            "id": 9,
            "user_id": 3
        },
        {
            "id": 10,
            "user_id": 4
        }
    ]

The first page from: 0, size: 4 should be:

    [
        {
            "id": 1,
            "user_id": 1
        },
        {
            "id": 5,
            "user_id": 2
        },
        {
            "id": 8,
            "user_id": 3
        },
        {
            "id": 10,
            "user_id": 4
        }
    ]

The second page from: 4, size 4 should be:

    [
        {
            "id": 2,
            "user_id": 1
        },
        {
            "id": 6,
            "user_id": 2
        },
        {
            "id": 9,
            "user_id": 3
        },
        {
            "id": 3,
            "user_id": 1
        }
    ]

Can I do such a thing?

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.