ElasticSearch Score Function Depending on Neighbor Documents

I have an ElasticSearch index with 2 mappings (types).
In the app I need to display a paginated feed containing items of both types.
Currently the items are sorted just by creation date, but I also want to have control on how the items alternate with each other on the page.
For example, if I have 300 documents of type "A" and 100 documents of type "B", I want to set a rule for sequence "3 items of type A, 1 item of type B, and so on".
I need it to make sure items of both types are displayed on each page and equally distributed across the pages.

But as far as I see it's not possible to access another documents in custom score function script.

Of course it's easy to implement directly in the app logic, but it's not clear how to implement pagination using this way.

Any ideas on how to achieve that?